codeline Posted August 17, 2010 Share Posted August 17, 2010 I'm having some trouble that I can't seem to figure out.. I've got a form with a file input area to upload an image. I just wanted to go through a if statement to check if a file was uploaded (which is required), however, even when I select a file to upload and submit, I still get the error echoing out as if nothing was uploaded. <?php if(!empty($_POST['submitFeature'])) { // set variables $featurename = mysql_real_escape_string($_POST['featurename']); $featuredesc = mysql_real_escape_string($_POST['featuredesc']); $src = $_FILES['featureupload']['tmp_name']; // 1 - A. REQUIRED FIELDS VERIFICATION if(!empty($featurename) && !empty($_FILES['featureupload']['tmp_name'])) { echo 'Image uploaded!'; } else { if (empty($_FILES['featureupload']['tmp_name'])) { echo 'No image uploaded.'; } } // 1 - B. END REQUIRED FIELDS ERROR CODES } ?> <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"> <div class="formSec"><label for="featurename" class="required">Feature Name:</label> <input type="text" name="featurename" id="featurename" value="" /></div> <div class="formSec"><label for="featureupload" class="required">Upload Feature:</label> <input type="hidden" class="hidden" name="max_file_size" value="9999999999999" /> <input type="file" name="featureupload" id="featureupload" /></div> <input class="submit" type="submit" name="submitFeature" value="Submit Your Feature" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/210935-check-if-file-was-uploaded-via-form/ Share on other sites More sharing options...
Adam Posted August 17, 2010 Share Posted August 17, 2010 You need to add the enctype attribute to your form with the value multipart/form-data in order to upload files: <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data"> Quote Link to comment https://forums.phpfreaks.com/topic/210935-check-if-file-was-uploaded-via-form/#findComment-1100285 Share on other sites More sharing options...
codeline Posted August 17, 2010 Author Share Posted August 17, 2010 oh man! the little things! I totally looked over that. thanks! Quote Link to comment https://forums.phpfreaks.com/topic/210935-check-if-file-was-uploaded-via-form/#findComment-1100460 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.