Page 1 of 1
Multiple File Uploading with php_ftp(functions)
Posted: Wed Jun 15, 2005 8:45 am
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?
Posted: Wed Jun 15, 2005 8:58 am
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
Posted: Wed Jun 15, 2005 8:58 am
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.
real code
Posted: Wed Jun 15, 2005 9:08 am
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.
so confused.
Posted: Wed Jun 15, 2005 9:38 am
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?
problem found
Posted: Wed Jun 15, 2005 10:49 am
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.