Conditional if statement for <input type="file">

Thread Solved

Join Date: Oct 2007
Posts: 260
Reputation: Venom Rush is an unknown quantity at this point 
Solved Threads: 2
Venom Rush's Avatar
Venom Rush Venom Rush is offline Offline
Posting Whiz in Training

Conditional if statement for <input type="file">

 
0
  #1
Jan 18th, 2008
I have a form that has an option to upload an image along with some text and a title. What I want to do is check if the input for uploading the image is empty. If it is then the page processes the code just to upload the text portion to the database. If it isn't empty then it processes the code that uploads the image as well as the text.

I used
  1. if (!$_POST['image']) {
which at first I thought did the trick but when I tried uploading an image it didn't work. I know for a fact that the code for uploading an image works as I've used it on another page to test it. So I'm left to believe that the conditional statement is the source of the problem.

Is there another way of checking if someone has browsed and chosen an image file for uploading?
This user has a spatula. We don't know why, but we are afraid.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,748
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 331
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Conditional if statement for <input type="file">

 
1
  #2
Jan 18th, 2008
  1. <?php
  2. if(isset($_POST['submit'])) {
  3. if($_FILES['fileupload']['name']==""){
  4. echo "Empty"; //no file was uploaded
  5. }
  6. //continue with rest of the operation..
  7. }
  8. ?>
  9. <html>
  10. <body>
  11. <form name="upload" method="post" action="upload.php" enctype="multipart/form-data">
  12. <table>
  13. <tr><td>
  14. <input type="file" name="fileupload">
  15. </td></tr>
  16. <tr><td>
  17. <input type="submit" name="submit">
  18. </td></tr>
  19. </table>
  20. </form>
  21. </body>
  22. </html>
This will do..
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 260
Reputation: Venom Rush is an unknown quantity at this point 
Solved Threads: 2
Venom Rush's Avatar
Venom Rush Venom Rush is offline Offline
Posting Whiz in Training

Re: Conditional if statement for <input type="file">

 
0
  #3
Jan 18th, 2008
I could kick myself right now. Thanks once again nav33n. May I one day be as incredibly smart as you are
This user has a spatula. We don't know why, but we are afraid.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,748
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 331
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Conditional if statement for <input type="file">

 
0
  #4
Jan 18th, 2008
You are welcome!
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 260
Reputation: Venom Rush is an unknown quantity at this point 
Solved Threads: 2
Venom Rush's Avatar
Venom Rush Venom Rush is offline Offline
Posting Whiz in Training

Re: Conditional if statement for <input type="file">

 
2
  #5
Jan 18th, 2008
Just for those that would like to know what I wanted the conditional statement for, here's an example:

  1. if ($_REQUEST['submit']) {
  2.  
  3. //checks if there is no image selected for uploading
  4. if ($_FILES['image']['name'] == '' ) {
  5.  
  6. //the code for inserting the text into the database
  7.  
  8. } else {
  9.  
  10. //the code for uploading the image and the text.
  11.  
  12. }
This user has a spatula. We don't know why, but we are afraid.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC