can someone help out and pin point out why this error occurs when I run my script.
here are the errors (the happen at the end of the script).
Warning: imagejpeg(): supplied argument is not a valid Image resource in C:\wamp\www\upload-system\upload2.php on line 271
Warning: imagedestroy(): supplied argument is not a valid Image resource in C:\wamp\www\upload-system\upload2.php on line 272
Warning: imagejpeg(): supplied argument is not a valid Image resource in C:\wamp\www\upload-system\upload2.php on line 271
Warning: imagedestroy(): supplied argument is not a valid Image resource in C:\wamp\www\upload-system\upload2.php on line 272
<?php
// Initialization
include('include/config.inc.php');
//include('include/session.php');
//if(!$session->logged_in) {
//header('location:msg.php?error=1');
//}
//else {
$result_final = '';
$counter = 0;
$maxSideLength = 768;
// List of our known photo 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'
);
// $filler_words = array('and', 'in',
// 'at', 'my',
// 'the', 'to'
// );
// 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'];
// Fetch the tags
$photo_tags = $_POST['tags'];
// Prep log file for writing
/*if(is_writable('../logs/'.$date.'.log') === TRUE) {
if(!$fileLog_handle = fopen('../logs/'.$date.'.log', 'a')) {
echo 'Server error!! Can not upload files. <br />';
exit();
}
}
else {
echo 'Server Error!! Log system is down. <br />';
exit();
}*/
// 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];
//$date_created = $photo_category[2];
//$date_updated = $photo_category[3];
if($photo_category[0]) {
$nameArray = explode(' ', $photo_category[0]);
$photo_category = join('_', $nameArray);
}
// Check to see if the category has a icon
$icon = (!isset($iconSet))? FALSE : TRUE;
// Start uploading and resizing images
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 {
// Insert the photo's info into the database
$sql = "INSERT INTO gallery_photos(photo_filename, photo_caption, photo_category) VALUES('0', '".addslashes($photo_caption[$counter])."', '".addslashes($photo_category_id)."')";
mysql_query($sql);
// Retrieve the ID from the last insert and create the new file name
$new_id = mysql_insert_id();
$filetype = $photos_uploaded['type'][$counter];
$extention = $photo_types[$filetype];
$filename = $new_id.".".$extention;
// Add a icon to the category
if($icon == FALSE) {
$sql = "UPDATE gallery_category SET category_icon='".addslashes('tb_'.$filename)."' WHERE category_id ='".addslashes((int)$photo_category_id)."'";
mysql_query($sql);
}
// Update the file name
$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;
/* Add this check
* Check to see if the image is great then 768 pixels wide and tall
* If the picture is wider or tall then the make lenght resize the picture and copy it to the server
* Else copy it to the server
*/
$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) {
// image exists
if($origwidth = imagesx($origimage) && $origheight = imagesy($origimage)) {
// Image is wider than tall
if($origwidth > $origheight && $origwidth > $maxSideLength) {
$width = (int)$maxSideLength; // wide images have a fixed width
$height = (int)($maxSideLength * ($origheight / $origwidth)); // calculate the height of the wider image
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
imagecopyresized($tmpimage, $origimage, 0, 0, 0, 0, $width, $height, $origwidth, $origheight);
// Save the resized image to the server
$function_to_write($tmpimage, $image_dir.'/'.$photo_category.'/images/'.$filename);
imagedestroy($tmpimage);
}
##############################################################
// Image is taller than wide
elseif($origheight > $origwidth && $origheight > $maxSideLength) {
$width = (int)($maxSideLength * ($origwidth / $origheight)); // calculate the width of a tall image
$height = (int)$maxSideLength; // tall images have a fixed height
// Create an image template based on the file's extension
if($function_suffix == $photo_types['image/gif'])
$tmpimage = imagecreate($width, $height);
else
$tmpimage = imagecreatetruecolor($width, $height);
imagecopyresized($tmpimage, $origimage, 0, 0, 0, 0, $width, $height, $origwidth, $origheight);
// Save the resized image to the server
$function_to_write($tmpimage, $image_dir.'/'.$photo_category.'/images/'.$filename);
imagedestroy($tmpimage);
}
else {
// Store the orignal file
move_uploaded_file($photos_uploaded['tmp_name'][$counter], $image_dir.'/'.$photo_category.'/images/'.$filename);
}
}
/*else {
echo 'Error during upload process. <br />';
$text = 'ERROR!! Could not retrieve the w/h of the original image: '.$image_dir.'/'.$photo_category.'/images/'.$filename.' for IP('.$_SERVER['REMOTE_ADDR'].')\n';
fwrite($fileLog_handle, $text);
exit();
}*/
}
/*else {
echo 'Error during the upload process. <br />';
$text = 'ERROR!! Could not find '.$image_dir.'/'.$photo_category.'/images/'.$filename.' to create the new image sizes for IP('.$_SERVER['REMOTE_ADDR'].')\n';
fwrite($fileLog_handle, $text);
exit();
}*/
?>