Jump to content

Fighting file upload:


washad

Recommended Posts

I'm trying to allow a user to upload a file (fairly new to PHP), but am having some difficulty getting a working example. To give credit, I'm using the book "PHP and MySQL Web Development" as my example.

 

My problem is that I get a blank value for  $_FILES['aboutImage']['tmp_name']. You can see that I try to echo the value (second code example) for testing purposes, but get nothing. I've stared at it quite some time and don't see anything obvious.

 

Thanks,

 

 

 

In my upload page, I have the following form:

 

          <form method="POST" action = "index.php?pageName=editConfirmPage" 
			enctype="multipart/form-data">
			<div>
				<input type="hidden" name="updateType" value="aboutImage"></input>
				<input type="hidden" name="MAX_FILE_SIZE" value="30000000"></input>
				<label for="aboutImage">Change About Image: </label>
				<input type="file" name="aboutImage" id="aboutImage"></input>
				<input type="submit" value="Send File"></input>
			</div>
		</form>	

 

In my response page, I have the following code:

 

$updateType = $sessioner->retrieveFromPost("updateType", NULL);

if ($updateType == "aboutImage") {

	echo "Uploading File<br/><br/>";

	if ($_FILE['aboutImage']['error'] > 0){
		echo "Problem!: <br/>";
		switch ($_FILE['aboutImage']['error']){
			case 1: 
			case 2:	echo "File too big";
				break;
			case 3: echo "File only partiall uploaded";
				break;
			default:
				echo "Problem uploading file";									
		}
		die();
	}

	$_fileSourcePath = $_FILES['aboutImage']['tmp_name'];
	$_fileName = basename($_FILES['aboutImage']['name']);
	$_fileDestinationPath = $FOLDER_PATHS['Abouts'].$_filename;

	echo $_fileSourcePath;
	echo $_fileDestinationPath;

	move_uploaded_file($_fileSourcePath, $_fileDestinationPath);

}

 

 

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

An empty $_FILES['aboutImage']['tmp_name'], since you are checking if the ['error'] element is > 0, could be caused by uploads not being enabled on your server or the size of the uploaded file exceeding the post_max_size setting (the entire $_FILES array will be empty.)

 

For debugging purposes, add the following to the start of your form processing code -

 

ini_set("display_startup_errors", "1");
ini_set("display_errors", "1");
error_reporting(E_ALL);
echo "<pre>";
echo "GET:";
print_r($_GET);
echo "POST:";
print_r($_POST);
echo "FILES:";
print_r($_FILES);
echo "</pre>";

 

What does a phpinfo(); statement show for the file_uploads setting?

Link to comment
https://forums.phpfreaks.com/topic/186633-fighting-file-upload/#findComment-985744
Share on other sites

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.