Forum Moderators: coopster

Message Too Old, No Replies

FTP upload

         

Phobia1

4:06 pm on Dec 4, 2008 (gmt 0)

10+ Year Member



Hi guys
Could anyone point me to the right place for help on this please.
so far I have made sure that from command prompt ftp->open works etc.

Where to begin?
Thanks
Fred

Little_G

5:10 pm on Dec 4, 2008 (gmt 0)

10+ Year Member



Hi,

You want to upload a file to a remote FTP server using PHP? If so look at the PHP manual section on built-in ftp functions [php.net], it gives an example of how to do that.

Andrew

Phobia1

5:16 pm on Dec 4, 2008 (gmt 0)

10+ Year Member



Hi
I have already done that but can't get ftp->connect to work.
have run php(info) on the server and all seems to be in order.
Best
Fred

Phobia1

4:23 pm on Dec 5, 2008 (gmt 0)

10+ Year Member



Hi Guys
I have got my ftp upload working, the web host only allows me to post to a tmp folder. Could anyone help me to move the file from tmp folder to another?
What I have so far is as below.
//upload.php
<form enctype="multipart/form-data" action="upload2.php" method="POST">
Please choose a file: <input name="uploaded" type="file" /><br />
<input type="submit" value="Upload" />
</form>

//upload2.php
<?php
$target = "/home/website/public_html/tmp/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;

//This is our size condition
if ($uploaded_size > 640000)
{
echo "Sorry Your file is too large.<br>";
$ok=0;
}

//This is our limit file type condition
if (isset($uploaded_type) && $uploaded_type =="text/jpg")
{
echo "Not an approved file type.";
$ok=0;
}

//Here we check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo "Sorry your file was not uploaded";
}

//If everything is ok we try to upload it
else
{
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES[’uploaded’][’name’]). " has been uploaded. Returning you to the uploads page.";

}
else
{
echo "Sorry, there was a problem uploading your file.";
}
}
?>

Back to reading, thanks in advance for any replies
Best
FJW