Page 1 of 1

File Upload Problems

Posted: Sun Oct 24, 2010 4:27 pm
by uchacker11
I am trying to setup a simple file upload script and its not working for some reason that I cannot figure out. I have /mnt/tmp setup as the temp directory and I want to upload a file to the server and store it there so I can look at it later. However, when I upload a file to the server nothing appears in the folder. Permissions on /mnt/tmp are 777. I am running php5 on Ubuntu.

php.ini - File Uploads
;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;

; Whether to allow HTTP file uploads.
; http://php.net/file-uploads
file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
; http://php.net/upload-tmp-dir
upload_tmp_dir = /mnt/tmp

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 8M

; Maximum number of files that can be uploaded via a single request
max_file_uploads = 20
Form:

Code: Select all

<form action="file_upload.php" method="post" enctype="multipart/form-data">
		<label for="file">Filename:</label>
			<input type="file" name="file" id="file" /> <br />
			<input type="submit" name="submit" value="Submit" />
	</form>
file_upload.php:

Code: Select all

if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES['file']['error'] . "<br />";
    }  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
    echo "Error Code: " . $_FILES['file']['error'] . "<br />";
    }
I have read multiple guides online and can not figure out why the files are not uploading. Any help is greatly appeciated.

Re: File Upload Problems

Posted: Sun Oct 24, 2010 5:20 pm
by s.dot
What is the output and what errors are you receiving? What is not working... the script or the moving the file to your target directory?

Turn error reporting on by putting the following at the top of file_upload.php

Code: Select all

ini_set('display_errors', 'On');
error_reporting(E_ALL)

Re: File Upload Problems

Posted: Sun Oct 24, 2010 5:31 pm
by uchacker11
When I turn on error reporting I get the error "Warning: move_uploaded_file(upload/Test.txt): failed to open stream: Permission denied in /mnt/sites/admin.jon-hacker.com/docs/file_upload.php on line 22 Warning: move_uploaded_file(): Unable to move '/mnt/tmp/phpmoNeTl' to 'upload/Test.txt' in /mnt/sites/admin.jon-hacker.com/docs/file_upload.php on line 22"

When I comment out the move_uploaded_file() portion of the script, nothing is created in /mnt/tmp either. I am thinking its a server config issue but just not sure what to check.

Re: File Upload Problems

Posted: Sun Oct 24, 2010 6:05 pm
by uchacker11
I figured it out. I had created the /mnt/tmp directory as root so the owner:group of the folder was root:root. Since I was executing the script as a lower user, even with the chmod 777 on the folder the script could not write to it. A simple chown web:web /mnt/tmp fixed the issue. Thanks for all your help.