Ok so basically I am creating a ftp loop, that takes dynamic inputs from a previous page (all variables should be present, but naturally may not be formatted correctly... or i wouldnt be posting)
So.. I can get it to loop through a connection just fine, but I seem to be having issues with $source_file and $destination_file as they print nothing on the page, and I get an ftp put error
Warning: ftp_put(): No file name in processFiles.php on line 228
FTP upload has failed!
If I could get someone to look at this and tell me whats going on.. I know that some of the other things may be wonky, but what I need help on is the destination and the source.... well, that and getting it to loop properly through to put the images in the right folders... any help would be appreciated
<?php
///checks the database
$host = "sqlhost" ;
$user = "sqlusername" ;
$pass = "sqlpass" ;
$db = "sqldbname" ;
$table="products";
$show_all = "SELECT * FROM $table ORDER BY Idnum";
mysql_connect ($host,$user,$pass) or die ( mysql_error ());
mysql_select_db ($db)or die ( mysql_error ());
$result = mysql_query ($show_all) or die ( mysql_error ());
$x=$_POST['uploadNeed'];
$counter=0;
while ($counter <$x){
$category=$_POST['radio'.$x];
$seasons=$_POST['seasons'.$x];
$products=$_POST['products'.$x];
$myfile=$_FILES['userfiles'.$x];
$imagename=$_FILES['userfiles'.$x]['name'];
// this counts the season folders
$fallcnt=0;
$falldirname="images/fall";
$falldn=opendir($falldirname);
while ($dircount=readdir($falldn))
{
$fallcnt=$fallcnt+1;
}
closedir ($falldn);
$fallcount=$fallcnt-1;
$wintercnt=0;
$winterdirname="images/winter";
$winterdn=opendir($winterdirname);
while ($dircount=readdir($winterdn))
{
$wintercnt=$wintercnt+1;
}
closedir ($winterdn);
$wintercount=$wintercnt-1;
$summercnt=0;
$summerdirname="images/summer";
$summerdn=opendir($summerdirname);
while ($dircount=readdir($summerdn))
{
$summercnt=$summercnt+1;
}
closedir ($summerdn);
$summercount=$summercnt-1;
$springcnt=0;
$springdirname="images/spring";
$springdn=opendir($springdirname);
while ($dircount=readdir($springdn))
{
$springcnt=$springcnt+1;
}
closedir ($springdn);
$springcount=$springcnt-1;
// end folder count
///upload image
// set up basic connection
$ftp_server="host";
$ftp_user_name="username";
$ftp_user_pass="password";
$conn_id = ftp_connect($ftp_server);
// login with username and password
$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 "<BR>Connected to $ftp_server, for user $ftp_user_name";
}
// upload the file
$currentdir=getcwd();
if ($category=="seasons"){
if ($seasons=="fall"){
$destination_file="images/fall/fall".$fallcount.".jpg";
}
elseif ($seasons=="winter"){
$destination_file="images/winter/winter".$wintercount.".jpg";
}
elseif ($seasons=="summer"){
$destination_file="images/summer/summer".$summercount.".jpg";
}
elseif ($seasons=="spring"){
$destination_file="images/spring/spring".$springcount.".jpg";
}
}
elseif ($products=="products"){
$destination_file="images/itempics/".$Idnum.".jpg";
}
elseif ($radio=="image"){
$destination_file="images/".$imagename."";
}
$source_file=$_FILES['userfiles'.$x]['tmp_name'];
print("<br>Source File: ".$source_file."<br>");
print("Destination File: ".$destination_file."<BR>");
///upload script
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
// check upload status
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file<BR><BR>";
///end upload script
}
///end upload file if file size is >0
// close the FTP stream
ftp_close($conn_id);
///end upload image
$counter=$counter+1;
}
?>