Forum Moderators: coopster

Message Too Old, No Replies

Php uploading file using FTP

         

Atomicus

3:20 pm on May 6, 2005 (gmt 0)



Hi I am having problem uploading files via FTP, but have a little bit of problem with the code, any help would be greatly appreciated. here is my code:

if (isset($_POST['Submitted'])) {
header('Content-type: image/jpeg');
$location = $_SERVER['DOCUMENT_ROOT'].'/common/pictures/';
$newFile = "test.jpg"; //$this->generateImageName($image).".".$this->getImageType($image);
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id,$login,$password);

// check connection
if ((!$conn_id) ¦¦ (!$login_result)) {
echo "FTP connection has failed!";
exit;
} else {
echo "Connected to Server!<br/>";
}
echo "File Destination: ". $location.$newFile."<br /> ";
echo "Temporary File: ". $_FILES["userfile"]["tmp_name"];
$upload = ftp_put($conn_id, $location.$newFile, $_FILES["userfile"]["temp_name"], FTP_BINARY);

// check upload status
if (!$upload) {
echo "Ftp upload has failed!";
} else {
echo "Uploaded successful";
}
ftp_close($conn_id);

}

output:


Connected to Server!<br/>File Destination: /usr/local/psa/home/vhosts/ksmarket.com/httpdocs/common/pictures/test.jpg<br /> Temporary File: /tmp/php0bX9Qk<br />
<b>Warning</b>: ftp_put(): /usr/local/psa/home/vhosts/example.com/httpdocs/common/pictures/test.jpg: No such file or directory in <b>/usr/local/psa/home/vhosts/example.com/httpdocs/admin/main/items/add.php</b> on line <b>31</b><br />
Ftp upload has failed!

the permission for the /common/pictures/ directory is set to 777.

thanks all for the help

[edited by: coopster at 12:26 pm (utc) on May 7, 2005]
[edit reason] generalized site specifics in directory path [/edit]

coopster

12:25 pm on May 7, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, Atomicus.

The message is telling you that the file and/or directory does not exist. Have you checked that both destination and source files/directories exist?