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.

Recommended Answers

All 7 Replies

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.

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'])){

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.

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.

Thank u very much

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

Member Avatar for diafol

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

That made a lot of sense!
POst your code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.