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;
}

?>

ok, then lets look at just what I am wanting to do... IE pull dynamic variables and in the end tell the php which folder to put them in as a loop


basically the person enters a category from a radiogroup on the previous page, its either a season, a product or an image.

it takes THAT category and then input from the drop downs that accompany (seasons obviously gets 1 of 4 selections thats passed) and products which has a large list with an Idnum sent.

now, the script has to look at these and go basically:

for each season that comes up, which season was it?... then put it in the right folder.

for products, it looks at the idnum and saves the image as $idnim.jpg

for images, it doesnt really care, it just saves it to a set folder, no renaming needed, although it DOES have to pick up the name from the specific dynamic userfile

my dynamic count variable from the previous page gets assigned as $x=$_POST['uploadneed']; and as you can see, I have the other variables being figured out as their dynamic versions:

$category=$_POST['radio'.$x];
$seasons=$_POST['seasons'.$x];
$products=$_POST['products'.$x];
$myfile=$_FILES['userfiles'.$x];
$imagename=$_FILES['userfiles'.$x]['name'];

now im not sure that $imagename is formatted correctly, as i said both destination and source prints nothing out, so probably do not have them formatted correctly.

the previous form, that sends data to this page, looks like this

<form name="fileup" method="post" enctype="multipart/form-data" action="processFiles.php">
  <?php
  // start of dynamic form
  $uploadNeed = $_POST['uploadNeed'];
  for($x=0;$x<$uploadNeed;$x++){
  ?>
<input name="userfiles<?php echo $x;?>" type="file" id="userfiles<?php echo $x;?>">
<input name="radio<?php echo $x?>" type="radio" value="seasons" />Seasons
<input name="radio<?php echo $x?>" type="radio" value="products" />Products
<input name="radio<?php echo $x?>" type="radio" value="Images" />Images<BR />
<?php include('includes/seasons.php'); ?>
<?php include('includes/products.php'); ?><BR /><BR /></font>
  <?php
  // end of for loop
  }  ?>

gah... stupid forum ate half my response. :(

so, yes basically the first page sets up how many upload fields are needed (requested by the client to be this way) then sends that information to the second page which then creates that many upload fields, radio groups and dropdowns (1 radio group and 2 dropdowns per upload field).

the process page looks at that and is suppose to loop through all information sent and put the files in the correct location based on the choices form the radio group and the drop downs..

the problem I seem to be having is somewhere in the way I am trying to recover the sourcefile (tmp name) and destination name (filename) from the $_FILES superglobal.

nothing is being printed, so i assume i am not actually retreiving the names correctly

I fixed it... yay... i used switch conditions

switch ($category){
	case 'seasons':
		$destination_file="images/".$seasons."/".$seasons."".$fallcount.".jpg";
		break;

	case 'products':
		$destination_file="images/itempics/".$products.".jpg";
		break;
	case 'images':
		$destination_file="images/".$newname."";
		break;
		}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.