Multiple File Uploading with php_ftp(functions)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
allan20850
Forum Newbie
Posts: 4
Joined: Wed Jun 15, 2005 8:31 am

Multiple File Uploading with php_ftp(functions)

Post by allan20850 »

I have this problem when trying to upload multiple files to a ftp-server. Basically I have one page post to $_POST a list of local files, and in the fileupload.php, I connect to the server, and can upload the first file in the array just fine. Everything else I receive an error about the file can't be found.

Im doing something like ** note psuedo code **
(for i = 0; i < file_count; i++)
{
fp = fopen(file_array)
if (!fp)
print "file loading error"; continue;

ftp_fput(con_stream, filename_dest, fp, ftp_binary);
fclose(fp);
}

I know i'm getting the right file name, maybe there is something I don't know about how html encodes files into a page?
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Code: Select all

tags want to smile around your code you all day long, today.

http://forums.devnetwork.net/viewtopic.php?t=21171
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

first of all you don't need to fopen if you are using ftp commands and plus what is your real code, we can't help you much without that.
allan20850
Forum Newbie
Posts: 4
Joined: Wed Jun 15, 2005 8:31 am

real code

Post by allan20850 »

This is the bulk of my problem, if I can get this to work, then i should be able to implement what i need to do.

Code: Select all

for ($i = 0; $i < $num; $i++)
{
  $fp[$i] = fopen($list[$i],"rb",true);
    if ($fp)
      print "file loaded<br>";
    else 
      print "error<br>";
}
$num, and $list are both already decleared and i've verified that they do contain what i need them to be.

$list is an array of file names containing the path.
ie 'C:\\temp\\filename.txt'

$num is the number of files in the array.
allan20850
Forum Newbie
Posts: 4
Joined: Wed Jun 15, 2005 8:31 am

so confused.

Post by allan20850 »

So if I do something like this

Code: Select all

$fp1 = fopen("C:\\temp\\file1.tmp","rb",true");
$fp2 = fopen("C:\\temp\\file2.tmp","rb",true");

ftp_fput($con_id,"f1",$fp1, FTP_BINARY);
ftp_fput($con_id,"f2",$fp2, FTP_BINARY);
That works, and when I use cuteftp to look at the files in the server, they both appear, f1 & f2. So why can't I do this in a for-loop?
allan20850
Forum Newbie
Posts: 4
Joined: Wed Jun 15, 2005 8:31 am

problem found

Post by allan20850 »

Found the problem. Basically whatever I did to the array when I built it from the previous page (which was made via a javascript), it added a whitespace (of which I don't know, nor do I care to go back and edit out which of the \n\t\0\r\x0 to find which one it is) and thats what was causing the fopen not to be able to find the file.
Post Reply