problem with image submit button

Reply

Join Date: Jun 2009
Posts: 17
Reputation: sandipan.rcciit is an unknown quantity at this point 
Solved Threads: 0
sandipan.rcciit sandipan.rcciit is offline Offline
Newbie Poster

problem with image submit button

 
0
  #1
Nov 9th, 2009
hi friends,
I already have a code that upload image with re size it.
  1. <form action="<?php echo $_server['php-self']; ?>" method="post" enctype="multipart/form-data" id="something" class="uniForm">
  2. <input name="new_image" id="new_image" size="30" type="file" class="fileUpload" />
  3. <input type="submit" name="submit" value="Submit"><p>
  4. </form>
  5. <?php
  6. if(isset($_POST['submit'])){
  7. if (isset ($_FILES['new_image'])){
  8. $imagename = $_FILES['new_image']['name'];
  9. $source = $_FILES['new_image']['tmp_name'];
  10. $target = "images/".$imagename;
  11. move_uploaded_file($source, $target);
  12.  
  13. $imagepath = $imagename;
  14. $save = "images/" . $imagepath; //This is the new file you saving
  15. $file = "images/" . $imagepath; //This is the original file
  16.  
  17. list($width, $height) = getimagesize($file) ;
  18.  
  19. $modwidth = 150;
  20.  
  21. $diff = $width / $modwidth;
  22.  
  23. $modheight = $height / $diff;
  24. $tn = imagecreatetruecolor($modwidth, $modheight) ;
  25. $image = imagecreatefromjpeg($file) ;
  26. imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
  27.  
  28. imagejpeg($tn, $save, 100) ;
  29. echo "Large image: <img src='images/".$imagepath."'><br>";
  30.  
  31.  
  32. }
  33. }
  34. ?>

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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 185
Reputation: venkat0904 is an unknown quantity at this point 
Solved Threads: 19
venkat0904's Avatar
venkat0904 venkat0904 is offline Offline
Junior Poster
 
0
  #2
Nov 9th, 2009
Thats simply because of this line..
  1. 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
  1. if(isset($_POST['submit_x'] && isset($_POST['submit_y'])){ // rest remains the same
hope this helps..
cheers!!!

Originally Posted by sandipan.rcciit View Post
hi friends,
I already have a code that upload image with re size it.
  1. <form action="<?php echo $_server['php-self']; ?>" method="post" enctype="multipart/form-data" id="something" class="uniForm">
  2. <input name="new_image" id="new_image" size="30" type="file" class="fileUpload" />
  3. <input type="submit" name="submit" value="Submit"><p>
  4. </form>
  5. <?php
  6. if(isset($_POST['submit'])){
  7. if (isset ($_FILES['new_image'])){
  8. $imagename = $_FILES['new_image']['name'];
  9. $source = $_FILES['new_image']['tmp_name'];
  10. $target = "images/".$imagename;
  11. move_uploaded_file($source, $target);
  12.  
  13. $imagepath = $imagename;
  14. $save = "images/" . $imagepath; //This is the new file you saving
  15. $file = "images/" . $imagepath; //This is the original file
  16.  
  17. list($width, $height) = getimagesize($file) ;
  18.  
  19. $modwidth = 150;
  20.  
  21. $diff = $width / $modwidth;
  22.  
  23. $modheight = $height / $diff;
  24. $tn = imagecreatetruecolor($modwidth, $modheight) ;
  25. $image = imagecreatefromjpeg($file) ;
  26. imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
  27.  
  28. imagejpeg($tn, $save, 100) ;
  29. echo "Large image: <img src='images/".$imagepath."'><br>";
  30.  
  31.  
  32. }
  33. }
  34. ?>

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.
Gimme reputation points if u find my post helpful.
use [code] tags wherever applicable
dont start a new thread unless u cant find the topic already on forum.
mark a thread "solved" as soon as u get a solution
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 557
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 64
network18 network18 is offline Offline
Posting Pro
 
0
  #3
Nov 9th, 2009
when you using
  1. <input type ="image" src="myfile.jpeg" name="submit" value="Submit">
use
  1. if(isset($_POST['submit_x']) && $_POST['submit_x'] !='' ){
instead of -
  1. if(isset($_POST['submit_x'])){
"The discipline of writing something down is the first step towards making it happen."

follow me on twitter
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 455
Reputation: Atli is on a distinguished road 
Solved Threads: 56
Atli's Avatar
Atli Atli is offline Offline
Posting Pro in Training
 
0
  #4
Nov 9th, 2009
Hey.

It's a LOT more stable to just do:
  1. <form action="script.php" method="post">
  2. <input type="hidden" name="isSubmitted" value="1">
  3. <input type="image" src="myfile.jpeg" name="submit" value="Submit">
  4. </form>
  1. <?php
  2. if(isset($_POST['isSubmitted'])) {
  3. // etc...
  4. }
  5. ?>

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.
Last edited by Atli; Nov 9th, 2009 at 4:30 pm.
Please do not ask for help in a PM. Use the forums.
And use [code] tags!
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 185
Reputation: venkat0904 is an unknown quantity at this point 
Solved Threads: 19
venkat0904's Avatar
venkat0904 venkat0904 is offline Offline
Junior Poster
 
0
  #5
Nov 10th, 2009
woooo... had no idea abt that submit button being missed out... nice info...
cheers !!!

Originally Posted by Atli View Post
Hey.

It's a LOT more stable to just do:
  1. <form action="script.php" method="post">
  2. <input type="hidden" name="isSubmitted" value="1">
  3. <input type="image" src="myfile.jpeg" name="submit" value="Submit">
  4. </form>
  1. <?php
  2. if(isset($_POST['isSubmitted'])) {
  3. // etc...
  4. }
  5. ?>

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.
Gimme reputation points if u find my post helpful.
use [code] tags wherever applicable
dont start a new thread unless u cant find the topic already on forum.
mark a thread "solved" as soon as u get a solution
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC