OK so this is where i am at with this and getting rather frustrated with it.
<?php
if (isset($_POST['sbmt'])):
$cat_id=$_REQUEST['cat_id'];
$propertyref=$_REQUEST['propertyref'];
for($i=0;$i<count($_FILES['foto']['tmp_name']);$i++):
if($_FILES['foto']['tmp_name']['$i']):
###### OLD INSERT QUERY #######
//$r=mysql_query("insert into pics(id) values ('" . $_REQUEST['id'] . "')");
//$pid=mysql_insert_id();
######## NEW PDO INSERT QUERY ##########
// insert new id into db, pid auto incrementally generated
try {
$r = "INSERT INTO `pics`(`id`) VALUES (:id)";
$q1 = $dbh->prepare($r);
$q1->bindvalue(':id', $_REQUEST['id']);
$q1->execute();
$pid = $dbh->lastInsertId(); // GET LAST pid FROM DB
} catch (PDOException $e) {
print "Error Inserting New Image!: " . $e->getMessage() . "<br/>";
die();
}
$e=explode(".",$_FILES['foto']['name'][$i]);
$ext=substr($_FILES['foto']['name'][$i],-3,3);
$size=$foto_size;
$ext=strtolower($e[1]);
if($ext=="peg"){$ext="jpg";}
copy($_FILES['foto']['tmp_name']['$i'],"images/" . $pid . "." . $ext);
copy($_FILES['foto']['tmp_name']['$i'],"images/thumb-" . $pid . "." . $ext);
/*
###### OLD UPDATE QUERY #######
//mysql_query("update pics set file='" . $pid . "." . $ext . "',thumb='thumb-" . $pid . "." . $ext . "' where pid=" . $pid);
*/
######## NEW PDO UPDATE QUERY ##########
//update db using new pid and ext from above
$file = $pid . "." . $ext ;
$thumb = "thumb-" . $pid . "." . $ext;
try {
$r2 = "UPDATE pics SET file = :file, thumb = :thumb WHERE pid =:pid";
$q2 = $dbh->prepare($r2);
$q2->bindParam(":file", $file);
$q2->bindParam(":thumb", $thumb);
$q2->bindParam(":pid", $pid);
$q2->execute();
$count2 = $q2->rowCount();
} catch (PDOException $e) {
print "Error Updating Image!: " . $e->getMessage() . "<br/>";
die();
}
$nw=145;$nh=133; //Size in pixels of thumbnail
$img=$tpath . "/thumb-" . $pid . "." . $ext;
$dimensions = GetImageSize($img);
$thname = $img;
$w=$dimensions['0'];
$h=$dimensions['1'];
if($ext=="jpg"):
$img2 = ImageCreateFromJpeg($img);
elseif($ext=="gif"):
$img2 = ImageCreateFromGif($img);
elseif($ext=="png"):
$img2 = ImageCreateFromPng($img);
endif;
$thumb=ImageCreateTrueColor($nw,$nh);
$wm = $w/$nw;
$hm = $h/$nh;
$h_height = $nh/2;
$w_height = $nw/2;
if($w > $h):
$adjusted_width = $w/$hm;
$half_width = $adjusted_width / 2;
$int_width = $half_width - $w_height;
ImageCopyResampled($thumb,$img2,-$int_width,0,0,0,$adjusted_width,$nh,$w,$h);
if($ext=="jpg"):
ImageJPEG($thumb,$thname,95);
elseif($ext=="gif"):
ImageGIF($thumb,$thname,95);
elseif($ext=="png"):
@ImagePNG($thumb,$thname,9);
endif;
elseif(($w < $h) || ($w == $h)):
$adjusted_height = $h / $wm;
$half_height = $adjusted_height / 2;
$int_height = $half_height - $h_height;
ImageCopyResampled($thumb,$img2,0,-$int_height,0,0,$nw,$adjusted_height,$w,$h);
if($ext=="jpg"):
ImageJPEG($thumb,$thname,95);
elseif($ext=="gif"):
ImageGIF($thumb,$thname,95);
elseif($ext=="png"):
ImagePNG($thumb,$thname,9);
endif;
else:
ImageCopyResampled($thumb,$img2,0,0,0,0,$nw,$nh,$w,$h);
if($ext=="jpg"):
ImageJPEG($thumb,$thname,95);
elseif($ext=="gif"):
ImageGIF($thumb,$thname,95);
elseif($ext=="png"):
ImagePNG($thumb,$thname,9);
endif;
endif;
imagedestroy($img2);
$target=550; //Size in pixels
$img=$tpath . "/" . $pid . "." . $ext;
$dimensions = GetImageSize($img);
$thname = $img;
$w=$dimensions['0'];
$h=$dimensions['1'];
$width=$w;
$height=$h;
if(($width>$target && $height>$target) || $width>$target):
$cent=100-round((($width-$target)/$width)*100);
$width=round($width*$cent/100);
$height=round($height*$cent/100);
elseif($height>$target):
$cent=100-round((($height-$target)/$height)*100);
$width=round($width*$cent/100);
$height=round($height*$cent/100);
endif;
if(($width>$target && $height>$target)|| $width>$target):
$cent=100-round((($width-$target)/$width)*100);
$width =round($width*$cent/100);
$height=round($height*$cent/100);
elseif($height>$target):
$cent=100-round((($height-$target)/$height)*100);
$width =round($width*$cent/100);
$height=round($height*$cent/100);
endif;
$nw=$width;$nh=$height;
if($ext=="jpg"):
$img2 = ImageCreateFromJpeg($img);
elseif($ext=="gif"):
$img2 = ImageCreateFromGif($img);
elseif($ext=="png"):
$img2 = ImageCreateFromPng($img);
endif;
$thumb=ImageCreateTrueColor($nw,$nh);
$wm = $w/$nw;
$hm = $h/$nh;
$h_height = $nh/2;
$w_height = $nw/2;
if($w > $h):
$adjusted_width = $w/$hm;
$half_width = $adjusted_width / 2;
$int_width = $half_width - $w_height;
ImageCopyResampled($thumb,$img2,-$int_width,0,0,0,$adjusted_width,$nh,$w,$h);
if($ext=="jpg"):
ImageJPEG($thumb,$thname,95);
elseif($ext=="gif"):
ImageGIF($thumb,$thname,95);
elseif($ext=="png"):
ImagePNG($thumb,$thname,9);
endif;
elseif(($w < $h) || ($w == $h)):
$adjusted_height = $h / $wm;
$half_height = $adjusted_height / 2;
$int_height = $half_height - $h_height;
ImageCopyResampled($thumb,$img2,0,-$int_height,0,0,$nw,$adjusted_height,$w,$h);
if($ext=="jpg"):
ImageJPEG($thumb,$thname,95);
elseif($ext=="gif"):
ImageGIF($thumb,$thname,95);
elseif($ext=="png"):
ImagePNG($thumb,$thname,9);
endif;
else:
ImageCopyResampled($thumb,$img2,0,0,0,0,$nw,$nh,$w,$h);
if($ext=="jpg"):
ImageJPEG($thumb,$thname,95);
elseif($ext=="gif"):
ImageGIF($thumb,$thname,95);
elseif($ext=="png"):
ImagePNG($thumb,$thname,9);
endif;
endif;
imagedestroy($img2);
endif;
endfor;
echo"<script>alert('Image successfully Updated');window.location.href='update-images.php?id=" . $_REQUEST['id'] . "&cat_id=" . $_REQUEST['cat_id'] . "&propertyref=" . $_REQUEST['propertyref'] . "';</script>";
endif;
include('nav.php');
echo "<h4 class='offset-by-eleven' id ='highlight'>Adding New Images</h4></div>";
echo ”;
print_r($_FILES['foto']);
/* RESULT OF PRINT ARRAY
Array
(
[name] => Array
(
[0] => buyers.jpg
[1] =>
[2] =>
[3] =>
[4] =>
[5] => contact1.png
[6] =>
[7] =>
[8] =>
[9] =>
)
[type] => Array
(
[0] => image/jpeg
[1] =>
[2] =>
[3] =>
[4] =>
[5] => image/png
[6] =>
[7] =>
[8] =>
[9] =>
)
[tmp_name] => Array
(
[0] => C:\\Windows\\Temp\\php232A.tmp
[1] =>
[2] =>
[3] =>
[4] =>
[5] => C:\\Windows\\Temp\\php232B.tmp
[6] =>
[7] =>
[8] =>
[9] =>
)
[error] => Array
(
[0] => 0
[1] => 4
[2] => 4
[3] => 4
[4] => 4
[5] => 0
[6] => 4
[7] => 4
[8] => 4
[9] => 4
)
[size] => Array
(
[0] => 13781
[1] => 0
[2] => 0
[3] => 0
[4] => 0
[5] => 75298
[6] => 0
[7] => 0
[8] => 0
[9] => 0
)
)
*/
echo ”;
?>
<!-- Add Images -->
<div class="add-image" > <!-- START FORM DIV -->
<form method="post" name="add" action="<?php echo $_SERVER['PHP_SELF']?>?propertyref=<?php echo $_REQUEST['propertyref'];?>" enctype="multipart/form-data">
<input type="hidden" name="id" value="<?php echo $_REQUEST['id']?>">
<input type="hidden" name="cat_id" value="<?php echo $_REQUEST['cat_id']?>">
<fieldset class="add-prop">
<legend class="sixteen columns">Adding images</legend>
<?php
for($i=1;$i<=10;$i++):
echo"<input type='file' class='image-upload' name='foto[]' >\
";
endfor;
?>
<br />
<input type="hidden" name="source" value="<?php echo $source?>">
<input type="hidden" name="thumb" value="<?php echo $thumb?>">
<input type="submit" class="image-upload" name="sbmt" value="Image Upload">
<br />
</fieldset>
</form>
</div>