| | |
Conditional if statement for <input type="file">
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
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 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?
I used
php Syntax (Toggle Plain Text)
if (!$_POST['image']) {
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.
php Syntax (Toggle Plain Text)
<?php if(isset($_POST['submit'])) { if($_FILES['fileupload']['name']==""){ echo "Empty"; //no file was uploaded } //continue with rest of the operation.. } ?> <html> <body> <form name="upload" method="post" action="upload.php" enctype="multipart/form-data"> <table> <tr><td> <input type="file" name="fileupload"> </td></tr> <tr><td> <input type="submit" name="submit"> </td></tr> </table> </form> </body> </html>
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
Just for those that would like to know what I wanted the conditional statement for, here's an example:
php Syntax (Toggle Plain Text)
if ($_REQUEST['submit']) { //checks if there is no image selected for uploading if ($_FILES['image']['name'] == '' ) { //the code for inserting the text into the database } else { //the code for uploading the image and the text. }
This user has a spatula. We don't know why, but we are afraid.
![]() |
Other Threads in the PHP Forum
- Previous Thread: doc to html
- Next Thread: object oriented php
| Thread Tools | Search this Thread |
apache api array beginner binary broken cache cakephp checkbox class cms code confirm cron curl customizableitems database date display dynamic echo email error external fcc file files folder form forms forum freelancing function functions google header headmethod howtowriteathesis href htaccess html iframe image include insert ip javascript joomla limit link login mail malfunction menu method mlm mod_rewrite multiple mysql neutrality oop pageing pagerank paypal pdf php phpmysql play problem query question radio random recursion remote root script search select server sessions sms soap source space sql support! syntax system table template tutorial update upload url validator variable video web youtube






