pcman Posted December 3, 2007 Share Posted December 3, 2007 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 https://forums.phpfreaks.com/topic/80024-how-can-i-check-if-the-user-upload-a-file/ Share on other sites More sharing options...
Caesar Posted December 3, 2007 Share Posted December 3, 2007 One approach... <?php if(file_exists($path_to_file.$file)) { echo'File was uploaded successfully'; } ?> Link to comment https://forums.phpfreaks.com/topic/80024-how-can-i-check-if-the-user-upload-a-file/#findComment-405558 Share on other sites More sharing options...
mr_mind Posted December 3, 2007 Share Posted December 3, 2007 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 https://forums.phpfreaks.com/topic/80024-how-can-i-check-if-the-user-upload-a-file/#findComment-405572 Share on other sites More sharing options...
pcman Posted December 4, 2007 Author Share Posted December 4, 2007 the problam is solved Link to comment https://forums.phpfreaks.com/topic/80024-how-can-i-check-if-the-user-upload-a-file/#findComment-405611 Share on other sites More sharing options...
cooldude832 Posted December 4, 2007 Share Posted December 4, 2007 Then hit the button ( Link to comment https://forums.phpfreaks.com/topic/80024-how-can-i-check-if-the-user-upload-a-file/#findComment-405616 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.