3

This is some very basic stuff. For a unknown reason i can't upload files via a standard HTML+PHP upload form.

The file doesn't exists locally under /tmp

php.ini

;;;;;;;;;;;;;;;;
; 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 = /tmp/

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

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

; open_basedir, if set, limits all file operations to the defined directory
; and below.  This directive makes most sense if used in a per-directory
; or per-virtualhost web server configuration file. This directive is
; *NOT* affected by whether Safe Mode is turned On or Off.
; http://php.net/open-basedir
open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/

; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
; http://php.net/post-max-size
post_max_size = 8M

upload code (resides in the same file as the html form, index.php)

print '<pre>';
print var_dump($_FILES);
print var_dump(is_uploaded_file($_FILES["file"]["tmp_name"]));
print is_writable('/tmp');
print '</pre>';

html

<form method="post" action="./" 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>

And my output is:

array(1) {
  ["file"]=>
  array(5) {
    ["name"]=>
    string(11) "test.jpg"
    ["type"]=>
    string(10) "image/jpeg"
    ["tmp_name"]=>
    string(14) "/tmp/php66JkW8"
    ["error"]=>
    int(0)
    ["size"]=>
    int(75766)
  }
}
bool(true)
1

permissions and info about the file:

[torxed@archie http]$ ls -l / | grep tmp
drwxrwxrwt   9 root root   220 Sep 26 13:34 tmp

[torxed@archie http]$ ls -lh /home/torxed/ | grep test
-rw-r--r--  1 torxed users  74K Sep 26 13:08 test.jpg
7
  • 1
    What is $files..??? Commented Sep 26, 2013 at 9:48
  • 2
    Missing _ and case sensitivity of variable names? $files !== $_FILES Commented Sep 26, 2013 at 9:49
  • Silly me, that solved the debug-output issue. Now to my original issue with this whole thing is that the file is never created (meaning, PHP or anything else for that matter) can't pick the file up. Commented Sep 26, 2013 at 9:55
  • You have something missing in your code. Action is ./ and not upload.php. Maybe you just moved the file from /tmp/ to /home/torxed/? Commented Sep 26, 2013 at 10:02
  • 1
    When using move_uploaded_file, this is fast even for big files, because it just changes the address of the file not its contents. The file doesn't get copied, it get's moved. If you don't use the uploaded temp file, its gone, that's what temporary is! Commented Sep 26, 2013 at 11:39

3 Answers 3

3

Solved it myself. As silly as the question is, the answer was even sillier.

[torxed@archie http]$ ls -lh /srv/http | grep tmp
drwxr-xr-x 2 torxed root 4.0K Sep 26 14:10 tmp

I assumed that the file would live under /tmp long enough for me to witness it being created which was stupid in the first place.

But trying to use move_uploaded_file returned false when trying to move it into ./ Cause of this was wrong permissions for the folder.

move_uploaded_file($src, '/srv/http' + $src); by simply moving it to another temporary location worked (after fixing the write permissions on /srv/http/tmp)

Sign up to request clarification or add additional context in comments.

1 Comment

I was about to tell you that you'll not be able to see the file while it's being created. Sometimes I don't understand downvoters nor their reasons to do it without a proper explanation.
1

Have you set post_max_size value to a higher one?

2 Comments

My bad, the default value (and i'll update my php.ini, is 8M)
I really have no idea, i voted up for pointing out i missed an important variable in my php.ini cut-out. Even tho that didn't fix the issue it was a well spotted miss on my part.
-1
var_dump(is_uploaded_file($_FILES["file"]["tmp_name"]));

1 Comment

This only solves my debug-output showing misguided information. The problem still remains that i can't access the local temporary file under /tmp since it's never created in the first place.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.