phpfreaks14 Posted November 1, 2007 Share Posted November 1, 2007 Hello Everybody, This is my first post in this forum. I have an issue related to a PHP script I have written to upload a file on the webserver. My script looks like: <?php if($_POST["upload_file"] == "Upload File") { if(!isset($_FILES) && isset($HTTP_POST_FILES)) $_FILES = $HTTP_POST_FILES; $uploaddir = '/Library/Webserver/Documents/Site/fileupload/uploaded_files/'; $uploadfile = $uploaddir . basename($_FILES['name_of_uploaded_file']['name']); if (move_uploaded_file($_FILES['name_of_uploaded_file']['tmp_name'], $uploadfile)) { echo "File is valid, and was successfully uploaded.\n"; } else { echo "Error in uploading the File\n"; } echo 'Here is some more debugging info:'; print_r($_FILES); } ?> <html> <body> <form method="POST" enctype="multipart/form-data" name="image_upload_form" action="<?php $_SERVER["PHP_SELF"]; ?>"> <p><input type="file" name="name_of_uploaded_file" size="200000"></p> <p><input type="submit" name="upload_file" value="Upload File"></p> </form> </body> </html> Now, when I upload the file I get following error: Error in uploading the File Here is some more debugging info:Array ( [name_of_uploaded_file] => Array ( [name] => DSC02548_1A.jpg [type] => image/jpeg [tmp_name] => /private/var/tmp/phpgbRgq8 [error] => 0 => 50502 ) ) It seems my file is not getting uploaded in the temporary folder. I have one more problem. I have changed the temporary file folder location in php.ini to upload_tmp_dir = /library/WebServer/Documents/temp/ (I have checked this value by phpinfo()) Now why am I getting the value of "tmp_name" as "/private/var/tmp/XYZ" and not as "/library/WebServer/Documents/temp/XYZ" ?? And why this code is not working? Please help me out. Thank you so much in advance. Quote Link to comment https://forums.phpfreaks.com/topic/75595-solved-file-upload-script-issue/ Share on other sites More sharing options...
phpfreaks14 Posted November 1, 2007 Author Share Posted November 1, 2007 Help me please...... Quote Link to comment https://forums.phpfreaks.com/topic/75595-solved-file-upload-script-issue/#findComment-382779 Share on other sites More sharing options...
rajivgonsalves Posted November 1, 2007 Share Posted November 1, 2007 well you'll have to restart your web server if you made changes to php.ini and php is running as a module... am looking at your code and seeing what could be the problem Quote Link to comment https://forums.phpfreaks.com/topic/75595-solved-file-upload-script-issue/#findComment-382804 Share on other sites More sharing options...
kellz Posted November 1, 2007 Share Posted November 1, 2007 why do people use: <?php $_SERVER["PHP_SELF"]; ?> in the form action? doesn't leaving it empty do the same thing? Quote Link to comment https://forums.phpfreaks.com/topic/75595-solved-file-upload-script-issue/#findComment-382818 Share on other sites More sharing options...
rajivgonsalves Posted November 1, 2007 Share Posted November 1, 2007 looking at your code it looks the file is getting uploaded properly there is a problem with your move command could be permission problems etc. Quote Link to comment https://forums.phpfreaks.com/topic/75595-solved-file-upload-script-issue/#findComment-382820 Share on other sites More sharing options...
phpfreaks14 Posted November 1, 2007 Author Share Posted November 1, 2007 looking at your code it looks the file is getting uploaded properly there is a problem with your move command could be permission problems etc. Thanks for your kind reply Rajiv. I restarted my Web Server: $ sudo /usr/sbin/apachectl restart Password: /usr/sbin/apachectl restart: httpd restarted Now the upload temp directory has been changed. But when I upload the file I still get: Error in uploading the File Here is some more debugging info:Array ( [name_of_uploaded_file] => Array ( [name] => DSC02548_1A.jpg [type] => image/jpeg [tmp_name] => /Library/WebServer/Documents/temp/phpukTA2d [error] => 0 => 50502 ) ) Could you please throw some more light? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/75595-solved-file-upload-script-issue/#findComment-382902 Share on other sites More sharing options...
phpfreaks14 Posted November 1, 2007 Author Share Posted November 1, 2007 looking at your code it looks the file is getting uploaded properly there is a problem with your move command could be permission problems etc. Thanks for your kind reply Rajiv. I restarted my Web Server: $ sudo /usr/sbin/apachectl restart Password: /usr/sbin/apachectl restart: httpd restarted Now the upload temp directory has been changed. But when I upload the file I still get: Error in uploading the File Here is some more debugging info:Array ( [name_of_uploaded_file] => Array ( [name] => DSC02548_1A.jpg [type] => image/jpeg [tmp_name] => /Library/WebServer/Documents/temp/phpukTA2d [error] => 0 => 50502 ) ) Could you please throw some more light? Thanks! The issue got resolved. There was permission issue. The directory in which I wanted to move the file did not have proper permissions. Now after changing the permission I am able to upload files. Thanks so much for your help! Quote Link to comment https://forums.phpfreaks.com/topic/75595-solved-file-upload-script-issue/#findComment-383068 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.