hellonoko Posted December 20, 2007 Share Posted December 20, 2007 I have a simple image upload page that uses the following form to upload the image: <form name="uploadimage" method="post" action="upload.php" enctype="multipart/form-data"> <input name="imagefile" type="file" size="100"> <input type="submit" name="Submit" value="upload"> </form> It works perfectly. However most of my submit buttons on related pages are now graphical... <form name="uploadimage" method="post" action="upload.php" enctype="multipart/form-data"> <input name="imagefile" type="file" size="100"> <input name="action" type="hidden" value="upload"> <input type="image" class="input_images" src="../images/add.png" alt="Upload"> </form> I believe the upload.php page is failing (as images are not uploaded) and thus I am receiving the below errors when the name of the image is passed on to the resize_image.php page for thumbnailing. (Im sure most of the errors will go away when the first one does) Why is the Submit Button working but not the Submit Image? Any idea? Thanks, ian Warning: copy(images/full/death-at-a-funeral-big.jpg) [function.copy]: failed to open stream: No such file or directory in C:\www\idea\gallery\resize_image.php on line 10 Warning: getimagesize(TEMP.jpg) [function.getimagesize]: failed to open stream: No such file or directory in C:\www\idea\gallery\resize_image.php on line 23 Warning: Division by zero in C:\www\idea\gallery\resize_image.php on line 25 Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in C:\www\idea\gallery\resize_image.php on line 31 Warning: imagecreatefromjpeg(TEMP.jpg) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in C:\www\idea\gallery\resize_image.php on line 32 Warning: imagecopyresampled(): supplied argument is not a valid Image resource in C:\www\idea\gallery\resize_image.php on line 34 Warning: imagejpeg(): supplied argument is not a valid Image resource in C:\www\idea\gallery\resize_image.php on line 39 Warning: copy(t_TEMP.jpg) [function.copy]: failed to open stream: No such file or directory in C:\www\idea\gallery\resize_image.php on line 47 Warning: unlink(t_TEMP.jpg) [function.unlink]: No such file or directory in C:\www\idea\gallery\resize_image.php on line 53 Warning: unlink(TEMP.jpg) [function.unlink]: No such file or directory in C:\www\idea\gallery\resize_image.php on line 54 Quote Link to comment Share on other sites More sharing options...
Jessica Posted December 20, 2007 Share Posted December 20, 2007 I doubt this is it, but your image does not have a name value. It would help if we see the PHP code, not just the errors. Quote Link to comment Share on other sites More sharing options...
hellonoko Posted December 20, 2007 Author Share Posted December 20, 2007 Here is the code! Form Code <style type="text/css"> <!-- input { color: #000000; background: #FFFFFF; border: 1px solid #000000; font-size: 10px; font-family: Arial, Helvetica, sans-serif; } .input_images { vertical-align:middle; color: #000000; background: #FFFFFF; border: 0px solid #FFFFFF; font-size: 10px; font-family: Arial, Helvetica, sans-serif; } --> </style> <form name="copyimage" method="post" action="copy.php" enctype="multipart/form-data"> <input name="action" type="hidden" value="copy" /> <input name="url" type="text" value="" size="100"><input name="filename" type="text" value="" size="20"> <input name="action" type="hidden" value="copy"> <input type="image" class="input_images" src="../images/add.png" alt="Add"> </form> <form name="uploadimage" method="post" action="upload.php" enctype="multipart/form-data"> <input name="imagefile" type="file" size="100"> <input type="submit" name="Submit" value="upload"> <input name="action" type="hidden" value="upload"> <input type="image" class="input_images" src="../images/add.png" alt="Upload"> </form> <?php $action = $HTTP_POST_VARS[action]; if ($action == "copy") { echo "copy"; } if ($action == "upload") { echo "upload"; } ?> Upload Code: <?php ini_set('display_errors', 1); error_reporting(E_ALL); //$submit = $_POST['Submit']; if (empty($_FILES['imagefile'])) { echo "<br><br>"; echo "Please choose a image to upload..."; die; } if(!empty( $_POST['Submit'] )) { //If the Submitbutton was pressed do: if ($_FILES['imagefile']['type'] == "image/jpeg") { $_FILES['imagefile']['name'] = str_replace(" ", "_", $_FILES['imagefile']['name']); copy ($_FILES['imagefile']['tmp_name'], "images/full/".$_FILES['imagefile']['name']) or die ("Could not copy"); echo "<br><br>"; echo "<b>File Uploaded...</b>"; } else { echo "<br><br>"; //echo "Could Not Copy... (".$_FILES['imagefile']['name'].")<br>"; echo "Could Not Copy... <br>"; die; } } echo "<br>"; $image_to_thumbnail = $_FILES['imagefile']['name']; //echo $image_to_thumbnail; include "resize_image.php"; echo "<br>"; echo "<img src=images/thumbs/t_".$image_to_thumbnail." />"; echo "<br>"; echo "<img src=images/full/".$image_to_thumbnail." />"; ?> Resize Image Code: <?php //get image to resize $source = 'images/full/'.$image_to_thumbnail; $dest = 'TEMP.jpg'; copy ( $source, $dest ); //Name you want to save your file as $file = $dest; $save = 't_'.$file; $size = 0.45; // header('Content-type: image/jpeg') ; list($width, $height) = getimagesize($file) ; $ratio = (250 / $height); $new_width = round($width * $ratio); $modwidth = $new_width; //$width * $size; $modheight = 250; //$height * $size; $tn = imagecreatetruecolor($modwidth, $modheight) ; $image = imagecreatefromjpeg($file) ; imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; // Here we are saving the .jpg, you can make this gif or png if you want //the file name is set above, and the quality is set to 100% imagejpeg($tn, $save, 100) ; // place thumbnail $source = $save; $dest = 'images/thumbs/t_'.$image_to_thumbnail; copy ( $source, $dest ); //clean up temp thumbnail and temp original $temp_original = "TEMP.jpg"; $temp_thumbnail = "t_TEMP.jpg"; unlink($temp_thumbnail); unlink($temp_original); echo "<b>Thumbnail Created...</b>"; echo "<br>"; ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted December 20, 2007 Share Posted December 20, 2007 First of all, you should make your resize code a function, instead of including another php file to run it. Instead of using copy I think you should use http://php.net/moveuploadedfile Quote Link to comment Share on other sites More sharing options...
hellonoko Posted December 20, 2007 Author Share Posted December 20, 2007 Yes I have not really.... Organized the code yet. I will take a look at move_uploaded_file but would still like to figure out why that image as submit button does not work. Quote Link to comment Share on other sites More sharing options...
revraz Posted December 21, 2007 Share Posted December 21, 2007 You do know that the name is "action" and not "submit" right? Quote Link to comment Share on other sites More sharing options...
hellonoko Posted December 21, 2007 Author Share Posted December 21, 2007 Yes. When you use an image as a submit button it submits the whole form. The hidden 'action' field is there so you know what image was hit. Quote Link to comment Share on other sites More sharing options...
Jessica Posted December 21, 2007 Share Posted December 21, 2007 That's what I meant by your image has no name. With the second one, there IS not $_POST['submit'] because no inputs have the name submit. Quote Link to comment Share on other sites More sharing options...
hellonoko Posted December 21, 2007 Author Share Posted December 21, 2007 Changed it to: if(!empty( $_POST['imagefile'] )) { //If the Submitbutton was pressed do: still no luck. 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.