Jump to content

Check if file was uploaded via form


codeline

Recommended Posts

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.