0

hi friends,
I already have a code that upload image with re size it.

<form action="<?php echo $_server['php-self'];  ?>" method="post" enctype="multipart/form-data" id="something" class="uniForm">
        <input name="new_image" id="new_image" size="30" type="file" class="fileUpload" />
 <input type="submit" name="submit" value="Submit"><p>
</form>
<?php
        if(isset($_POST['submit'])){
          if (isset ($_FILES['new_image'])){
              $imagename = $_FILES['new_image']['name'];
              $source = $_FILES['new_image']['tmp_name'];
              $target = "images/".$imagename;
              move_uploaded_file($source, $target);
              
              $imagepath = $imagename;
              $save = "images/" . $imagepath; //This is the new file you saving
              $file = "images/" . $imagepath; //This is the original file

              list($width, $height) = getimagesize($file) ; 
                                                         
              $modwidth = 150; 
                                                         
              $diff = $width / $modwidth;
                                                        
              $modheight = $height / $diff; 
              $tn = imagecreatetruecolor($modwidth, $modheight) ; 
              $image = imagecreatefromjpeg($file) ; 
              imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 
                                                        
              imagejpeg($tn, $save, 100) ; 
            echo "Large image: <img src='images/".$imagepath."'><br>"; 
        
        
          }
        }
?>

and its working fine.
but i have a problem when i use
<input type ="image" src="myfile.jpeg" name="submit" value="Submit">

in the position of

<input type="submit" name="submit" value="Submit">

image upload cannot act.i cant understand what is the problem and how to resolve it????
plz help me.

7
Contributors
7
Replies
13
Views
8 Years
Discussion Span
Last Post by diafol
0

Thats simply because of this line..

if(isset($_POST['submit'])){

when u use an image for input, it doesnt post values as "name"="value" as it does in case of buttons..
instead it will post name_x=... and name_y=... where the values are the x & y coordinates of the point where user clicks the image..
modify ur code to

if(isset($_POST['submit_x'] && isset($_POST['submit_y'])){ // rest remains the same

hope this helps..
cheers!!!

hi friends,
I already have a code that upload image with re size it.

<form action="<?php echo $_server['php-self'];  ?>" method="post" enctype="multipart/form-data" id="something" class="uniForm">
        <input name="new_image" id="new_image" size="30" type="file" class="fileUpload" />
 <input type="submit" name="submit" value="Submit"><p>
</form>
<?php
        if(isset($_POST['submit'])){
          if (isset ($_FILES['new_image'])){
              $imagename = $_FILES['new_image']['name'];
              $source = $_FILES['new_image']['tmp_name'];
              $target = "images/".$imagename;
              move_uploaded_file($source, $target);
              
              $imagepath = $imagename;
              $save = "images/" . $imagepath; //This is the new file you saving
              $file = "images/" . $imagepath; //This is the original file

              list($width, $height) = getimagesize($file) ; 
                                                         
              $modwidth = 150; 
                                                         
              $diff = $width / $modwidth;
                                                        
              $modheight = $height / $diff; 
              $tn = imagecreatetruecolor($modwidth, $modheight) ; 
              $image = imagecreatefromjpeg($file) ; 
              imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 
                                                        
              imagejpeg($tn, $save, 100) ; 
            echo "Large image: <img src='images/".$imagepath."'><br>"; 
        
        
          }
        }
?>

and its working fine.
but i have a problem when i use
<input type ="image" src="myfile.jpeg" name="submit" value="Submit">

in the position of

<input type="submit" name="submit" value="Submit">

image upload cannot act.i cant understand what is the problem and how to resolve it????
plz help me.

0

when you using

<input type ="image" src="myfile.jpeg" name="submit" value="Submit">

use

if(isset($_POST['submit_x']) && $_POST['submit_x'] !='' ){

instead of -

if(isset($_POST['submit_x'])){
0

Hey.

It's a LOT more stable to just do:

<form action="script.php" method="post">
    <input type="hidden" name="isSubmitted" value="1">
    <input type="image" src="myfile.jpeg" name="submit" value="Submit">
</form>
<?php
if(isset($_POST['isSubmitted'])) {
    // etc...
}
?>

You should never actually test to see if the submit button was sent, because there are cases where the button is left out. For instance, if you submit the form by pressing the Enter button, certain browsers do not include the submit button.

It's best to always test a data field, or add a hidden field specifically for that purpose.

Edited by Atli: n/a

0

woooo... had no idea abt that submit button being missed out... nice info...
cheers !!!

Hey.

It's a LOT more stable to just do:

<form action="script.php" method="post">
    <input type="hidden" name="isSubmitted" value="1">
    <input type="image" src="myfile.jpeg" name="submit" value="Submit">
</form>
<?php
if(isset($_POST['isSubmitted'])) {
    // etc...
}
?>

You should never actually test to see if the submit button was sent, because there are cases where the button is left out. For instance, if you submit the form by pressing the Enter button, certain browsers do not include the submit button.

It's best to always test a data field, or add a hidden field specifically for that purpose.

0

how to fix a button image using isset why can not function

That made a lot of sense!
POst your code.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.