washad Posted December 30, 2009 Share Posted December 30, 2009 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); } Quote Link to comment https://forums.phpfreaks.com/topic/186633-fighting-file-upload/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 30, 2009 Share Posted December 30, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/186633-fighting-file-upload/#findComment-985744 Share on other sites More sharing options...
washad Posted December 30, 2009 Author Share Posted December 30, 2009 Thanks for your help, It was enough to push me over the hump. The error reporting identified the fact that I use $_FILE, instead of $_FILES in my error checking - so I didn't notice that the file was too big - which was indeed the problem. SteveJ Quote Link to comment https://forums.phpfreaks.com/topic/186633-fighting-file-upload/#findComment-985753 Share on other sites More sharing options...
PFMaBiSmAd Posted December 30, 2009 Share Posted December 30, 2009 That's what error reporting helps with the most, things too small to see and easy to overlook. Quote Link to comment https://forums.phpfreaks.com/topic/186633-fighting-file-upload/#findComment-985755 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.