Jump to content

Recommended Posts

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\">";

?>

Link to comment
https://forums.phpfreaks.com/topic/196842-upload-file-help/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/196842-upload-file-help/#findComment-1033343
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/196842-upload-file-help/#findComment-1033678
Share on other sites

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

 

Link to comment
https://forums.phpfreaks.com/topic/196842-upload-file-help/#findComment-1033687
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.