DarkHavn Posted September 1, 2006 Share Posted September 1, 2006 I keep getting these two random errors, here are the errors[quote]Warning: imagecopyresampled(): supplied argument is not a valid Image resource in C:\xampp\xampp\htdocs\localfind\catalogue\update\images.php on line 44Warning: imagedestroy(): supplied argument is not a valid Image resource in C:\xampp\xampp\htdocs\localfind\catalogue\update\images.php on line 51[/quote]and heres the code[code]if($_POST['next']) {//foreach ($_FILES["image"]["error"] as $key => $error) {$maxfilesize = 734349;$mimetype = array('image/pjpeg','image/jpeg','image/jpg'); if($_FILES['image']['size'][$key] >= $maxfilesize){ $errormsg = 'Remember you can not upload a file larger than 700kb, and only .jpg images are allowed!'; break; // move_uploaded_file($tmp_name, "data/$name"); } else { $tmp_name = $_FILES["image"]["tmp_name"][$key]; $name = $_FILES["image"]["name"][$key]; $filesize = $_FILES['image']['size'][$key]; // This is the temporary file created by PHP $uploadedfile = $_FILES['image']['tmp_name'][$key];// Create an Image from it so we can do the resize$src = imagecreatefromjpeg($uploadedfile);// Capture the original size of the uploaded imagelist($width,$height)=getimagesize($uploadedfile);// For our purposes, I have resized the image to be// 600 pixels wide, and maintain the original aspect // ratio. This prevents the image from being "stretched"// or "squashed". If you prefer some max width other than// 600, simply change the $newwidth variable$newwidth = 600;$newheight = 400;$tmp=imagecreatetruecolor($newwidth,$newheight);// this line actually does the image resizing, copying from the original// image into the $tmp imageimagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); // now write the resized image to disk. I have assumed that you want the// resized, uploaded image file to reside in the ./images subdirectory.$filename = "../../clients/$bname/images". $_FILES['image']['name'];imagejpeg($tmp,$filename,100);imagedestroy($src);imagedestroy($tmp);[/code]i dunno what's going on, i thought everything was valid, but apparently not?? Quote Link to comment Share on other sites More sharing options...
Caesar Posted September 1, 2006 Share Posted September 1, 2006 Can you please post the entire code? Quote Link to comment Share on other sites More sharing options...
DarkHavn Posted September 2, 2006 Author Share Posted September 2, 2006 Ok heres the entire code[code]<?session_start();//welcome to the images section, this section allows you to upload four images.//load them into the thumb or large images and they will show on your libraryif($_POST['next']) {//foreach ($_FILES["image"]["error"] as $key => $error) {$maxfilesize = 734349;$mimetype = array('image/pjpeg','image/jpeg','image/jpg'); if($_FILES['image']['size'][$key] >= $maxfilesize){ $errormsg = 'Remember you can not upload a file larger than 700kb, and only .jpg images are allowed!'; break; // move_uploaded_file($tmp_name, "data/$name"); } else { $tmp_name = $_FILES["image"]["tmp_name"][$key]; $name = $_FILES["image"]["name"][$key]; $filesize = $_FILES['image']['size'][$key]; // This is the temporary file created by PHP $uploadedfile = $_FILES['image']['tmp_name'][$key];// Create an Image from it so we can do the resize$src = imagecreatefromjpeg($uploadedfile);// Capture the original size of the uploaded imagelist($width,$height)=getimagesize($uploadedfile);// For our purposes, I have resized the image to be// 600 pixels wide, and maintain the original aspect // ratio. This prevents the image from being "stretched"// or "squashed". If you prefer some max width other than// 600, simply change the $newwidth variable$newwidth = 600;$newheight = 400;$tmp=imagecreatetruecolor($newwidth,$newheight);// this line actually does the image resizing, copying from the original// image into the $tmp imageimagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); // now write the resized image to disk. I have assumed that you want the// resized, uploaded image file to reside in the ./images subdirectory.$filename = "../../clients/$bname/images". $_FILES['image']['name'];imagejpeg($tmp,$filename,100);imagedestroy($src);imagedestroy($tmp);// NOTE: PHP will clean up the temp file it created when the request// has completed./* $size = 150; // the thumbnail height $filedir = 'pics/'; // the directory for the original image $thumbdir = 'pics/'; // the directory for the thumbnail image $prefix = 'small_'; // the prefix to be added to the original name $maxfile = '2000000'; $mode = '0666'; $userfile_name = $_FILES['image']['name']; $userfile_tmp = $_FILES['image']['tmp_name']; $userfile_size = $_FILES['image']['size']; $userfile_type = $_FILES['image']['type']; if (isset($_FILES['image']['name'])) { $prod_img = $filedir.$userfile_name; $prod_img_thumb = $thumbdir.$prefix.$userfile_name; move_uploaded_file($userfile_tmp, $prod_img); chmod ($prod_img, octdec($mode)); $sizes = getimagesize($prod_img); $aspect_ratio = $sizes[1]/$sizes[0]; if ($sizes[1] <= $size) { $new_width = $sizes[0]; $new_height = $sizes[1]; }else{ $new_height = $size; $new_width = abs($new_height/$aspect_ratio); } $destimg=ImageCreateTrueColor($new_width,$new_height) or die('Problem In Creating image'); $srcimg=ImageCreateFromJPEG($prod_img) or die('Problem In opening Source Image'); if(function_exists('imagecopyresampled')) { imagecopyresampled($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die('Problem In resizing'); }else{ Imagecopyresized($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die('Problem In resizing'); } ImageJPEG($destimg,$prod_img_thumb,90) or die('Problem In saving'); imagedestroy($destimg); } /*switch($_FILES['image']['type'][$key]){case 'image/jpeg': case 'image/pjpeg': case 'image/jpg': $bname = $_SESSION['clients']; //Alright type to cut these images up. $realwidth = 150; $realheight = 150; imagecreatetruecolor($realwidth, $realheight); //print_r(gd_info()); //Sets the path of where to save the images $path = "../../../Clients/$bname"; break; }*/ //}}}//there is a file limit for each file, and only acceps .jpgecho "$errormsg";unset($error);echo "<form method='post' enctype='multipart/form-data' action=" . $_SERVER['PHP_SELF'] . "><br/>"; echo "Thumb nails:<br/><input type='file' name='image[]'>File Name:<input type='text' name='filename'><br/>"; /*echo "<input type='file' name='image[]'>File Name:<input type='text' name='filename1'><br/>"; echo "<input type='file' name='image[]'>File Name:<input type='text' name='filename2'><br/>"; echo "<input type='file' name='image[]'>File Name:<input type='text' name='filename3'><br/>"; echo "Large Images:<br/><input type='file' name='image1'>File Name:<input type='text' name='filename4'><br/>"; echo "<input type='file' name='image[]'>File Name:<input type='text' name='filename5'><br/>"; echo "<input type='file' name='image[]'>File Name:<input type='text' name='filename6'><br/>"; echo "<input type='file' name='image[]'>File Name:<input type='text' name='filename7'><br/>"; */ echo "<input type='submit' value='Save and proceed to the next section' name='next'>";echo "</form>";?>[/code] Quote Link to comment Share on other sites More sharing options...
DarkHavn Posted September 2, 2006 Author Share Posted September 2, 2006 Figured out what was going as, due to the fact that i had the form name='image[]'So it was set as an array, and before hand i was looping through an array, but since i had commented out the foreach loop, it was still picking up the value as an array, due to those lovley two brackets.My next question is, i've got it to resize a 600x400, but i also want a smaller thumb, how would that be possible without stuffing around with to much of my code? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.