I have the following code that checks the image size and then copies it to my website folder as well as saves it to the database as a path. The problem Im having is that it uploads the images to my server correctly, but when it saves them in my database it isn't showing the 2nd or 3rd image name that I uploaded with the script it only saves the name as the first images name. I hope this makes sense. Please help me.
if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1")) {
//////////////////////Image Upload////////////////////////////
/// Count Amount Of Images ///
$path = getcwd();
chdir('my/directory/path');
$adminpath = getcwd();
$count=count($_FILES['file']['name']);
$i=0;
//////////////////////////////
$maxfilesize=150000;
$imsize=$_FILES['file']['size'];
$immaxwidth="600";
$immaxheight="600";
$picname = $_FILES['file']['name'];
$updir = "$adminpath/customerimages";
//////////////////////////////
/// Start Loop ///
while($i < $count) {
$check = $_FILES['file']['size'][$i];
if($check !='0') //if a file was uploaded in this field
{ echo "<br>start run $i";
echo $_FILES['file']['name'][$i];
//////////////////
//check image width & height
$imgsize = GetImageSize($file);
//== check size 0=width, 1=height
if (($imgsize[0] > $immaxwidth) || ($imgsize[1] > $immaxheight)){
$msg ="ERROR - Image width and height allowed is $immaxwidth by $immaxheight px. Please select an image that meets this requirement.";
}
//end dimension check
else if (file_exists("$updir/$picname")){
$msg = "ERROR - Your file was not saved!";
$msg = "File name already exists, please rename your file!";
unlink($_FILES['file']['tmp_name'][$i]);
}
else if (!is_uploaded_file($HTTP_POST_FILES['file']['tmp_name'][$i])){
$msg = "ERROR = You did not upload a file!";
unlink($_FILES['file']['tmp_name'][$i]);
}
else if ($_FILES['file']['size'][$i] > $maxfilesize){
$msg = "ERROR - File is over 150k in size";
unlink($_FILES['file']['tmp_name'][$i]);
}
else if ($_FILES['file']['type'][$i] != "image/pjpeg"){
$msg = "ERROR - This file type is not allowed. Only .jpg or .jpeg is allowed.";
unlink($_FILES['file']['tmp_name'][$i]);
}
// else here we go upload and save image to database
else {
mysql_select_db($database_erotic, $erotic);
$memberid = mysql_query("SELECT id FROM escorts WHERE username='". $_POST['membername'] . "'");
$getmemberid = mysql_fetch_array($memberid);
if ($i =='0'){
$images[] = $_FILES['file']['name'][$i];
$insertdate = "now()";
move_uploaded_file($_FILES['file']['tmp_name'][$i],"$adminpath/customerimages/" . $_FILES['file']['name'][$i]);
$insertSQL= sprintf("INSERT INTO images SET id='$getmemberid', photo$i='$images[0]', status='pending', date='$insertdate'");
mysql_select_db($database_erotic, $erotic);
$Result1 = mysql_query($insertSQL, $erotic) or die(mysql_error());
} else {
$images[] = $_FILES['file']['name'][$i];
$insertdate = "now()";
move_uploaded_file($_FILES['file']['tmp_name'][$i],"$adminpath/customerimages/" . $_FILES['file']['name'][$i]);
$insertSQL= sprintf("UPDATE images SET photo$i='$images[0]', status='pending', date=$insertdate WHERE id='$getmemberid'");
mysql_select_db($database_erotic, $erotic);
$Result1 = mysql_query($insertSQL, $erotic) or die(mysql_error());
}
////testing thumbnail script////
@$size = GetImageSize("$adminpath/customerimages/" . $_FILES['file']['name'][$i]);
//this creates a temp image from JPEG//
if ($size[2] == '2'){
@$source_id = imagecreatefromjpeg("$adminpath/customerimages/" . $_FILES['file']['name'][$i]);
$dest_x = 100;
$dest_y = 100;
@$target_id = imagecreatetruecolor($dest_x, $dest_y);
@$target_pic = imagecopyresampled($target_id,$source_id, 0, 0, 0, 0, $dest_x, $dest_y, $size[0],$size[1]);
$test="imagejpeg";
}
// save thumbnail at 100 resolution //
if ($test == 'imagejpeg'){
@imagejpeg($target_id,"$adminpath/customerimages/thumb/thumb_" . $_FILES['file']['name'][$i], 100);
$insertthumb=sprintf("UPDATE images SET thumb$i='thumb_" . $_FILES['file']['name'][$i] . "' WHERE photo$i='" . $_FILES['file']['name'][$i] . "'");
mysql_select_db($database_erotic, $erotic);
$Result2 = mysql_query($insertthumb, $erotic) or die(mysql_error());
}
/////////// end thumbnail script /////////////////////
$msg = "Your image was successfully uploaded!";
}
}
// ends the if a file was uploaded loop
else{
}
$i++;
}
}