Jump to content

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

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.