I am running an upload for images within a while loop. Somewhere within the coding it is only uploading 1 file whereas the variable ($UploadNum) is looking for 12 files.
I am thinking that the script is not stalling to wait for the ftp to upload before trying to upload another file... is there any way to make this work?
// create & upload files
$num = 0;
// set up basic connection
$ftpid = ftp_connect($ftp_server)
or die("Connection Timed Out/Failed.");
// login with username and password
$login_result = ftp_login($ftpid, "$ftp_user_name", "$ftp_user_pass")
or die("Couldn't Connect/Log In.");
// check connection
if (!$login_result) {
die("FTP Connection Failed.");
}
// get pictures
while($num < $UploadNum) {
$num++;
$picture = "fileup$num"."_name";
$picture1 = $$picture;
$picture2 = "fileup$num";
$picture3 = $$picture2;
// check to see if there is a picture in that field
if($picture3 == $null) {
$error .= "No picture for file $num<BR>";
$ok = 2;
}
// check file size
if($picture3 != "none") {
$filesizebtyes = filesize($picture3);
$ok = 1;
// error if file size is less than 10 bytes
if($filesizebtyes < 10) {
$error .= "Error uploading (file size lower than 10 bytes) for file $num<BR>";
$ok = 2;
}
// check if file exists else upload via ftp
if(file_exists("$UploadDir/$LE[mlsid] - $LE[mlsaddr]/$picture1") OR $ok == 2) {
$error .="File name already exists for file $num<BR>";
}
elseif (ftp_pwd($ftpid) == "/home/listingenhancers/www/users/$memuser/$LE[mlsid] - $LE[mlsaddr]") {
$upload = ftp_put($ftpid, "$picture1", "$picture3", FTP_BINARY);
$ext = strrchr("$UploadDir/$LE[mlsid] - $LE[mlsaddr]/$picture1",'.');
ftp_rename ($ftpid, "$picture1","$LE[mlsid]"."-"."$num"."$ext");
$error .="File $num has been uploaded<BR>";
if ($num = $UploadNum) {
ftp_quit($ftpid);
}
}
else {
ftp_chdir($ftpid, "/home/listingenhancers/www/users/")
or die("Could Not Change to Directory");
if (! @ftp_chdir($ftpid,"$memuser")) {
// check for directory - if none make and change
ftp_mkdir($ftpid,"$memuser");
ftp_chdir($ftpid,"$memuser");
}
else {
// exists - change to directory
ftp_chdir($ftpid, "$memuser");
}
if (! @ftp_chdir($ftpid,"$LE[mlsid] - $LE[mlsaddr]")) {
// check for directory - if none make and change
ftp_mkdir($ftpid,"$LE[mlsid] - $LE[mlsaddr]");
ftp_chdir($ftpid,"$LE[mlsid] - $LE[mlsaddr]");
}
else {
// exists - change to directory
ftp_chdir($ftpid, "$LE[mlsid] - $LE[mlsaddr]");
}
$upload = ftp_put($ftpid, "$picture1", "$picture3", FTP_BINARY);
$ext = strrchr("$UploadDir/$LE[mlsid] - $LE[mlsaddr]/$picture1",'.');
ftp_rename ($ftpid, "$picture1", "$LE[mlsid]"."-"."$num"."$ext");
$error .="File $num has been uploaded<BR>";
if ($num = $UploadNum) {
ftp_quit($ftpid);
}
}
}
}
// no files have been selected
if(!$error) {
$error .= "No files have been selected for upload";
}