Jump to content

Help with multiple File Uploads PHP 4


RendarProphecy

Recommended Posts

Hello,

I've working on a script that will read through a directory on my local intranet server, create an array with all of it's contents, then ftp it to a remote server. I have done a CHMOD 777 to the directory I want to upload to, I'm able to read through and return the contents of the Array (or image files in the directory).


But, for some reason, I keep getting the error:

 

Warning: ftp_put(u6c8D.jpg) [function.ftp-put]: failed to open stream: No such file or directory in C:\apache\Apache2\htdocs\advertising\classified\open_house\admin\export_csv\ftp.php on line 80

 

(this is one of the elements of the array, they all list... u6c8D.jpg is one of the images in the directory)


I assume it's something with my directory structure or the probably more obvious syntax, but I've tried moving the directories, and even putting my ftp.php file into the images directory... still no luck. Any advice would be appreciated.

 

Here's my code. Please bear in mind... I'm still kinda new at PHP and I've "borrowed" most of the code below. :o)

 

<?php

// set up basic connection
$ftp_server = "MY-FTP-SERVER";
$conn_id = ftp_connect($ftp_server); 

// login with username and password
$ftp_user_name = "MY-FTP-USERNAME";
$ftp_user_pass = "MY-FTP-PASS";
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 

// check connection
if ((!$conn_id) || (!$login_result)) { 
       echo "FTP connection has failed!";
       echo "Attempted to connect to $ftp_server for user $ftp_user_name"; 
       exit; 
   } else {
       echo "Connected to $ftp_server, for user $ftp_user_name<br><br>\n";
   }

//remote directory
$uploadDir = "/maps/open_house/images";

//local image directory
$dir = "../../image/";

$dh  = opendir($dir);
while (false !== ($filename = readdir($dh))) {
    $files[] = $filename;
}

sort($files);

print_r($files);

rsort($files);

print_r($files);
echo "<br>";

//$upload = ftp_put($conn_id, $files, $uploadDir, FTP_BINARY); 
foreach( $files as $key => $value){
ftp_put($conn_id, $uploadDir, $value, FTP_BINARY);
}

// echo results to make sure you're getting the correct info
//TESTING ONLY REMOVE WHEN FINISHED
echo "<p> <hr><strong>Upload Directory:</strong> $uploadDir";
echo "<br><strong>home directory:</strong> $dir";
echo "<br><strong>files:</strong> $files";
//---------------------------------------------------------------------------------

// close the FTP stream 
ftp_close($conn_id); 

?>

Link to comment
Share on other sites

Looks to me like your FTP server path isn't correct. Are you on a shared host? The paths are usually something different then what you think.

Try creating an empty PHP script and echo out $_SERVER['SCRIPT_FILENAME'] and see what it says. Oh, put it in the folder your trying to access and put that path in your FTP script and test again.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.