Jump to content

Submit Image returns error Submit Button does not.


hellonoko

Recommended Posts

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

Link to comment
Share on other sites

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>";
?> 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.