jandrews3 Posted March 29, 2010 Share Posted March 29, 2010 The following code comes from two pages, one which selects the file and the other which actually uploads it. The two files work perfectly on one server but give the result "No File Selected" when I use it on a new server to which I am moving. Auugghhh!!! Page 1: <form action="uploader_b.php" method="post" enctype="multipart/form-data" style="margin-bottom: 0;"> <input type="file" name="file"> <input type="hidden" name="version"> <input type="submit" value="Upload File"> </form> Page 2: <?php extract($_REQUEST); if ($file_name !="") { $filename = $_FILES["file"]["name"]; copy ("$file", "documents/$file_name") or die("Could not copy file"); } else { die("No file specified"); } $filename = $file_name; print "<META HTTP-EQUIV=\"Refresh\" content=\"0;URL=admin_cpanel.php\">"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/196842-upload-file-help/ Share on other sites More sharing options...
premiso Posted March 29, 2010 Share Posted March 29, 2010 Why are you extracting $_REQUEST? Why not just access them via the way you expect them to come in from? IE: <?php if (isset($_FILES["file"] && !empty($_FILES["file"]["name"]) { $filename = $_FILES["file"]["name"]; copy ("$file", "documents/$file_name") or die("Could not copy file"); } // Why do a meta refresh? // print "<META HTTP-EQUIV=\"Refresh\" content=\"0;URL=admin_cpanel.php\">"; // header works pretty well: header("Location: admin_cpanel.php"); ?> Should work like you want it to. Not sure where file_name is even coming from to be honest, seems like we may be missing a piece of the puzzle, but that should work. Quote Link to comment https://forums.phpfreaks.com/topic/196842-upload-file-help/#findComment-1033343 Share on other sites More sharing options...
eje Posted March 29, 2010 Share Posted March 29, 2010 Also, be sure you have the correct permissions set in your target folder. Quote Link to comment https://forums.phpfreaks.com/topic/196842-upload-file-help/#findComment-1033349 Share on other sites More sharing options...
jandrews3 Posted March 29, 2010 Author Share Posted March 29, 2010 The permissions is set correctly. If also put in the code you suggested: if (isset($_FILES["file"]) && !empty($_FILES["file"]["name"])) { $filename = $_FILES["file"]["name"]; copy ("$file", "documents/$file_name") or die("Could not copy file"); } but still get no results. The fact that my coding worked on one server but not on another tells me it may be a server setting issue. Has anyone had any experience with server settings which may cause this script to fail. Quote Link to comment https://forums.phpfreaks.com/topic/196842-upload-file-help/#findComment-1033678 Share on other sites More sharing options...
PFMaBiSmAd Posted March 29, 2010 Share Posted March 29, 2010 The code you posted is just way out of date AND it has absolutely no error checking logic, no error reporting logic, or error recovery logic in it to get it to check if the upload worked or failed, tell you why it failed, and take an appropriate action when it fails. For debugging purposes only, to find out what is happening on the server, add the following code starting on the line right after the first opening <?php tag - ini_set("display_startup_errors", "1"); ini_set("display_errors", "1"); error_reporting(E_ALL); echo "<pre>"; echo "POST:"; print_r($_POST); echo "FILES:"; print_r($_FILES); echo "</pre>"; Quote Link to comment https://forums.phpfreaks.com/topic/196842-upload-file-help/#findComment-1033687 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.