ok so I have made a couple post about this one script. I am still kind of newbish but have been working with php for about 9 months on and off. I am just getting back into is after a 4 month break and have returned to try and finish my first php project. The script that I have been working months on worked flawlessly, but after my computer crashed and I reinstalled everything but as it use to be it seems to not be working anymore. So I was wondering if any of you php experts or just plain nice folks out there could help a php hobbyist find the problems with his script. I do know that when I do try to upload a file my script returns to me that the file is smaller than 0bytes.
here is my code
<?php
// Initialization
include('include/config.inc.php');
include('include/galleryFunc.inc.php');
error_reporting(E_ALL);
$result_final = '';
$counter = 0;
$maxSideLength = 768;
// List of our known photo formats based on mime types
$photo_types = array('image/pjpeg'=>'jpg',
'image/jpeg'=>'jpg',
'image/gif'=>'gif',
'image/bmp'=>'bmp',
'image/png'=>'png');
// GD Function List
$gd_function_suffix = array('image/pjpeg'=>'jpeg',
'image/jpeg'=>'jpeg',
'image/gif'=>'gif',
'image/bmp'=>'wbmp',
'image/png'=>'png');
// Fetch the photo array sent by preupload.php
$photos_uploaded = $_FILES['photo_filename'];
// Fetch the photo caption array
$photo_caption = $_POST['photo_caption'];
// Fetch the photo category id
$photo_category_id = (int)$_POST['category'];
//$photo_category_id = 2;
// Fetch the tags
$photo_tags = $_POST['tags'];
// Retrive the category's name, icon name, dates when created and updated from the database
$sql = 'SELECT category_name, category_icon FROM gallery_category WHERE category_id="'.addslashes((int)$photo_category_id).'"';
$results = mysql_query($sql);
$photo_category = mysql_fetch_row($results);
$iconSet = $photo_category[1];
$category = $photo_category[0];
if($photo_category[0]) {
$nameArray = explode(' ', $photo_category[0]);
$photo_category = join('_', $nameArray);
}
$icon = (!isset($iconSet))? FALSE : TRUE;
if(count($photos_uploaded) == 0)
echo $msg = 'No Photos to Upload';
else {
while($counter < count($photos_uploaded)) {
if($photos_uploaded['size'][$counter] > 0) {
if(!array_key_exists($photos_uploaded['type'][$counter], $photo_types))
$result_final .= 'File '.($counter+1).' is not a photo<br />';
else {
$sql = 'INSERT INTO gallery_photos(photo_filename, photo_caption, photo_category, photo_date) VALUES("0", "'.addslashes($photo_caption[$counter]).'", "'.addslashes($photo_category_id).'", NOW())';
mysql_query($sql);
$new_id = mysql_insert_id();
$filetype = $photos_uploaded['type'][$counter];
$extention = $photo_types[$filetype];
$filename = $new_id.".".$extention;
if($icon == FALSE) {
$sql = 'UPDATE gallery_category SET category_icon="'.addslashes('tb_'.$filename).'" WHERE category_id ="'.addslashes((int)$photo_category_id).'"';
mysql_query($sql);
}
$sql = 'UPDATE gallery_photos SET photo_filename="'.addslashes($filename).'" WHERE photo_id="'.addslashes((int)$new_id).'"';
mysql_query($sql);
// Start the gd image manipulation process
$function_suffix = $gd_function_suffix[$filetype];
// Instead of finding out which output function to use by testing the extension,
// just use the extension to create the function
$function_to_read = 'imagecreatefrom'.$function_suffix;
$function_to_write = 'image'.$function_suffix;
$origimage = $function_to_read($photos_uploaded['tmp_name'][$counter]);
// Create the main image with a max limit of a side as 768 pixels
if($origimage) {
$origwidth = imagesx($origimage);
$origheight = imagesy($origimage);
if(isset($origwidth) && isset($origheight)) {
if($origwidth < $maxSideLength && $origheight < $maxSideLength) {
move_uploaded_file($photos_uploaded['tmp_name'][$counter], 'photos/'.$photo_category.'/images/'.$filename);
}
// Image is wider than tall
elseif($origheight > $maxSideLength || $origwidth > $maxSideLength) {
if($origwidth > $origheight) {
$width = (int)$maxSideLength; // wide images have a fixed width
$height = (int)($maxSideLength * ($origheight / $origwidth)); // calculate the height of the wider image
}
// Image is taller than wide
elseif($origheight > $origwidth) {
$width = (int)($maxSideLength * ($origwidth / $origheight));
$height = (int)$maxSideLength;
}
// Create an image template based on the file's extension
if($function_suffix == $photo_types['image/gif']) // Create an image template based on the file's extension
$tmpimage = imagecreate($width, $height); // Create a blank image for a gif file
else
$tmpimage = imagecreatetruecolor($width, $height); // Create a blank image for every other image format
imagecopyresampled($tmpimage, $origimage, 0, 0, 0, 0, $width, $height, $origwidth, $origheight);
// Save the resized image to the server
$function_to_write($tmpimage, 'photos/'.$photo_category.'/images/'.$filename);
imagedestroy($tmpimage);
}
}
}
######################################################################
# Create Thumbnails
######################################################################
$size = getimagesize('photos/'.$photo_category.'/images/'.$filename);
// Wide image
if($size[0] > $size[1]) {
$thumbnail_height = 100;
$thumbnail_width = (int)(100 * ($size[1] / $size[0])) + 100;
}
// Tall image
elseif($size[1] > $size[0]) {
$thumbnail_height = (int)(100 * ($size[0] / $size[1])) + 100;
$thumbnail_width = 100;
}
// Image already 100 x 100
else
$thumnail_width = $thumbnail_height = 100;
$source_handle = $function_to_read('photos/'.$photo_category.'/images/'.$filename);
if(isset($source_handle)) {
echo 'source handle is set in thumb creation section<br />';
if($function_suffix == $photo_types['image/gif'])
$destination_handle = imagecreate($thumnail_width, $thumbnail_height) or die('image create failed');
else
$destination_handle = imagecreatetruecolor($thumbnail_width, $thumbnail_height) or die('image create true color failed');
// Take the blank file image(destination_handle) and fill it with the uploaded image($source_handle)
imagecopyresized($destination_handle, $source_handle, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $size[0], $size[1]);
$function_to_write($destination_handle, 'photos/'.$photo_category.'/thumbs/tb_'.$filename);
// Destroy Handle
imagedestroy($destination_handle);
}
###################################################################
# beginning of squaring images
###################################################################
if($thumbnail_width > $thumbnail_height) { // Wide Image
$posx = (int)$thumbnail_width / 4;
$posy = 0;
}
elseif($thumbnail_height > $thumbnail_width) { // Tall Image
$posy = (int)$thumbnail_height / 4;
$posx = 0;
}
else
$posy = $posx = 0;
$source_handle = $function_to_read('photos/'.$photo_category.'/thumbs/tb_'.$filename);
if(isset($source_handle)) {
echo 'source handle set in squaring section<br />';
if($function_suffix == $photo_types['image/gif'])
$destination_handle = imagecreate(100, 100) or die('image create falied');
else
$destination_handle = imagecreatetruecolor(100, 100) or die('image create true color failed');
imagecopyresampled($destination_handle, $source_handle, 0, 0, $posx, $posy, 100, 100, 100, 100) or die('image resize failed');
$function_to_write($destination_handle, 'photos/'.$photo_category.'/thumbs/tb_'.$filename);
imagedestroy($destination_handle);
}
// final results
$result_final[] = '<img class="reflect" src="photos/'.$photo_category.'/thumbs/tb_'.$filename.'" border ="0" alt="" />';
}
$msg = 'These pictures have been uploaded into '.$category;
}
else {
$msg = 'file is to small';
}
$counter++;
echo $counter.'<br />';
}
// Update the the gallery_update field in the category table
$sql = 'UPDATE gallery_category SET category_date_updated = "NOW()" WHERE category_id ="'.addslashes((int)$photo_category_id).'"';
mysql_query($sql);
//$msg = 'These pictures have been uploaded into '.$category;
}
?>