Forum Moderators: coopster

Message Too Old, No Replies

Dynamic variables within a LOOP - Need quick help

Dynamic variables within a LOOP - Need quick help

         

PSWorx

4:43 am on Dec 13, 2005 (gmt 0)

10+ Year Member



Ok, problem, running through this loop to upload a thumb and large image of origonal one provided, and to generate names for the database for each upload.

The problem is it wont assign the name for the second and third itteration properly, instead of being the VALUE its the name of the DYNAMIC VARIABLE, all files are uploaded correctly, all other entries in the database are fine including the first picture name, it just fails to work on the last two loops of the for statement.

CODE (Sorry for the mess) :
----------------------------------------------------
//Create a for loop for the product pictures 3 is the limit
//Set loop var to 0 just incase
$abc=0;
//do for loop
for($abc=1; $abc<=3; $abc++){
//Check for upload file and its name - if not available set the DATA SET var to NULL else do upload
if( isset($_FILES['picName_' .$abc. '']) && $_FILES['picName_' .$abc. '']['name']!="" ){
//Check for type and prepare extension var as required
//FOR GIF
if($_FILES['picName_' .$abc. '']['type']=="image/gif"){
$fileExt = ".gif";
//FOR JPG/JPEG
}elseif(
//Because of microsoft
($_FILES['picName_' .$abc. '']['type']=="image/pjpeg") ¦¦
//For everyone else
($_FILES['picName_' .$abc. '']['type']=="image/jpeg") ¦¦
//Just incase
($_FILES['picName_' .$abc. '']['type']=="image/jpg") ){
$fileExt = ".jpg";
//FOR PNG
}elseif($_FILES['picName_' .$abc. '']['type']=="image/png"){
$fileExt = ".png";
//ANYTHING ELSE REDIRECT USER WITH NOTE
}else{
$_SESSION['adminSession']['editNote']='Unknown file type, please use either .GIF .JPG/JPEG or .PNG files. - <a href="' .$_SERVER['HTTP_REFERER']. '#prods">Continue</a>';
$redirectAfterUpdate=$_SERVER['HTTP_REFERER'];
header("Location: $redirectAfterUpdate");
}
//
//Start preppping image names
//Start preppping image names
//
//Prep image name for datebase - dynamic var used
$var='prodPicName' .$abc;
${$var}=$catLink. '-' .$subCatLink. '-' .$_POST['supplierCode']. '-' .$abc.$fileExt;
//Rename uploaded file to go with image name in database
$_FILES['picName_' .$abc. '']['name']=${$var};
//First set for creating thumbnails
//Image dir for use with copy function - location loaded from config.php
$imageDIR=$varSub.$_SERVER['productThumbImage_dir'];
//Thumbnail image location
$imageFile=$imageDIR.$_FILES['picName_' .$abc. '']['name'];
//Do copy of file
copy($_FILES['picName_' .$abc. '']['tmp_name'], $imageDIR.$_FILES['picName_' .$abc. '']['name'])or die("Could not copy");
$tn_image = new Thumbnail($imageDIR.$_FILES['picName_' .$abc. '']['name'], $_SERVER['smallMaxWidth'], $_SERVER['smallMaxHeight'], 0);
$tn_image->save($imageDIR.$_FILES['picName_' .$abc. '']['name']);
//Second set for creating large images
//Image dir for use with copy function - location loaded from config.php
$imageDIR=$varSub.$_SERVER['productLargeImage_dir'];
//Large image location
$imageFile=$imageDIR.$_FILES['picName_' .$abc. '']['name'];
//Do copy of file
copy($_FILES['picName_' .$abc. '']['tmp_name'], $imageDIR.$_FILES['picName_' .$abc. '']['name'])or die("Could not copy");
$tn_image = new Thumbnail($imageDIR.$_FILES['picName_' .$abc. '']['name'], $_SERVER['largeMaxWidth'], $_SERVER['largeMaxHeight'], 0);
$tn_image->save($imageDIR.$_FILES['picName_' .$abc. '']['name']);
}else{
//If no image uploaded set as no image for default place holder dynamic var being used here
$var='prodPicName' .$abc;
${$var}=NULL;
}
}

Any help in the next hour or so would be tops.

TIA

PSWorx

5:27 am on Dec 13, 2005 (gmt 0)

10+ Year Member



Pardom me for being an idiot, problem solved

Thanks to those who were about to reply

LOL