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
https://forums.phpfreaks.com/topic/210935-check-if-file-was-uploaded-via-form/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.