idlelimey Posted October 29, 2009 Share Posted October 29, 2009 Hi, I have written a very simple file upload script but it fails for reasons I can't explain. Hopefully someone here can help me out. I have checked php.ini and file uploads are on with a limit of 10M. Here's the code: The Form <form enctype="multipart/form-data" action="upload.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> And the PHP $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {echo "File has been uploaded";} else {echo "The upload did not work.";} Any help is appreciated. Assuming the target path should be [dir where the form and php are]/uploads - this exists and is 777'd. Thank you Quote Link to comment Share on other sites More sharing options...
scvinodkumar Posted October 29, 2009 Share Posted October 29, 2009 could you please tell me what error u getting? Quote Link to comment Share on other sites More sharing options...
priti Posted October 29, 2009 Share Posted October 29, 2009 Hey this work fine at my end testme.php <form enctype="multipart/form-data" action="upload.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> upload.php <?php $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {echo "File has been uploaded";} else {echo "The upload did not work.";} ?> /uploads exists in the same dir where these scripts are placed and it's 777. It works smoothly @ my end I received no error. Quote Link to comment Share on other sites More sharing options...
idlelimey Posted October 29, 2009 Author Share Posted October 29, 2009 Thank you both. Sorry, I should have been clearer in my original post. I believe the code to be fine (it worked for priti, thanks ), there's not really a lot to go wrong with it. My assumption is that there is a configuration issue at the server which is preventing me from performing the upload (I get the 'else{echo "The upload did not work.";}' bit). I am comparing two different setups (one that works, one that doesn't) at the minute to try and narrow down the problem but I'm drawing a blank. Can anyone tell me any specific settings at the server end that enable file uploads? Or, for that matter, any common settings that would fail uploads? Thanks again, I am grateful for the help. Quote Link to comment Share on other sites More sharing options...
idlelimey Posted October 29, 2009 Author Share Posted October 29, 2009 Have just discovered the: $_FILES['uploadedfile']['error'] and the returned value is '6', which apparently means I am missing a temporary folder. I will look in to this some more and report back. Any assistance on temporary folders most welcome! Quote Link to comment Share on other sites More sharing options...
priti Posted October 29, 2009 Share Posted October 29, 2009 okie good going let us know if you get stuck :-) Quote Link to comment Share on other sites More sharing options...
jcombs_31 Posted October 29, 2009 Share Posted October 29, 2009 Have you checked your php.ini for the upload_tmp_dir = directive? Quote Link to comment Share on other sites More sharing options...
idlelimey Posted October 29, 2009 Author Share Posted October 29, 2009 Okay, problem solved. I have written to the host (it's on a shared service) and requested they setup a 'upload_tmp_dir'. That'll work. Well worth checking for anybody setting up an uploader to check the values in php.ini that will effect it. I am guessing that 'upload_tmp_dir' usually has a default setting of '/tmp' but the host in this case has removed it. For the record, there seems no way of the user setting this on the fly using .htaccess or any other similar method. Thanks for the help! Quote Link to comment Share on other sites More sharing options...
idlelimey Posted October 29, 2009 Author Share Posted October 29, 2009 Have you checked your php.ini for the upload_tmp_dir = directive? I just missed your post. That's exactly where the problem was. Thank you for replying. Quote Link to comment 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.