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 ;)

Link to comment
Share on other sites

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.';
}
?>

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.