Jump to content

how can i check if the user upload a file?


pcman

Recommended Posts

i have this form:

 

 

php:

<?php
if(isset($_POST['send']))
{

if($_FILES['pic']['name'] != "")
{
echo "this will be show all the time=[";
}
else
{
echo "no file uploaded";
}

}
else
{
echo '
<form action="lala.php" method="post"  enctype="multipart/form-data">
<input type="file" name="benzona" />

<input type="submit" name="send">
<form>
';
}
?>

 

if i dos'nt upload a file the if is still print "this will be show all the time=["...

what can i do to solve this problam...?

 

thy ;)

Try this. tell me if it works.

 

<?php
if($_POST['send'] && !(isset($message) || isset($error)) {
	if($_FILES['pic']['name'] != "") {
		if($_FILES['pic']['error']==0) {
			$message = 'File sent';
		}
		else {
			$error = 'Error: ' . $_FILES['pic']['error'] . '. Please notify the site admin.';
		}
	}
	else {
		$error = 'You must submit a file';
	}
}
elseif($_POST['send'] && (isset($message) || isset($error))) {
	if(isset($message)) {
		print $message;
	}
	else {
		print $error;
		print '<form action=lala.php method=post enctype=multipart/form-data>';
		print '<label for=pic>Picture File: </label><input type=file name=pic id=pic value="' . $_POST['pic'] . '" /><br />';
		print '<input type=submit name=send value=Upload>';
		print '<form>';
	}
}
elseif(!$_POST['send']) {
	print '<form action=lala.php method=post enctype=multipart/form-data>';
	print '<label for=pic>Picture File: </label><input type=file name=pic id=pic /><br />';
	print '<input type=submit name=send value=Upload>';
	print '<form>';
}
else {
	print 'An unknown error has occured. Please notify the site admin.';
}
?>

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.