944,066 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1318
  • PHP RSS
Nov 9th, 2009
0

problem with image submit button

Expand Post »
hi friends,
I already have a code that upload image with re size it.
PHP Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
sandipan.rcciit is offline Offline
25 posts
since Jun 2009
Nov 9th, 2009
0
Re: problem with image submit button
Thats simply because of this line..
PHP Syntax (Toggle Plain Text)
  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
PHP Syntax (Toggle Plain Text)
  1. 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.
PHP Syntax (Toggle Plain Text)
  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.
Reputation Points: 13
Solved Threads: 21
Junior Poster
venkat0904 is offline Offline
186 posts
since Oct 2009
Nov 9th, 2009
0
Re: problem with image submit button
when you using
PHP Syntax (Toggle Plain Text)
  1. <input type ="image" src="myfile.jpeg" name="submit" value="Submit">
use
PHP Syntax (Toggle Plain Text)
  1. if(isset($_POST['submit_x']) && $_POST['submit_x'] !='' ){
instead of -
PHP Syntax (Toggle Plain Text)
  1. if(isset($_POST['submit_x'])){
Reputation Points: 29
Solved Threads: 76
Practically a Master Poster
network18 is offline Offline
616 posts
since Sep 2009
Nov 9th, 2009
0
Re: problem with image submit button
Hey.

It's a LOT more stable to just do:
html Syntax (Toggle Plain Text)
  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>
php Syntax (Toggle Plain Text)
  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.
Reputation Points: 93
Solved Threads: 70
Posting Pro
Atli is offline Offline
526 posts
since May 2007
Nov 10th, 2009
0
Re: problem with image submit button
woooo... had no idea abt that submit button being missed out... nice info...
cheers !!!

Click to Expand / Collapse  Quote originally posted by Atli ...
Hey.

It's a LOT more stable to just do:
html Syntax (Toggle Plain Text)
  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>
php Syntax (Toggle Plain Text)
  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.
Reputation Points: 13
Solved Threads: 21
Junior Poster
venkat0904 is offline Offline
186 posts
since Oct 2009
Jul 24th, 2010
0
Re: problem with image submit button
Thank u very much
Reputation Points: 10
Solved Threads: 0
Newbie Poster
shandesilva is offline Offline
1 posts
since Jul 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Javascript in PHP not working Help plz
Next Thread in PHP Forum Timeline: Where Can I Get on Website?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC