【发布时间】:2013-09-26 21:08:38
【问题描述】:
这是一些非常基本的东西。 由于未知原因,我无法通过标准 HTML+PHP 上传表单上传文件。
文件在本地/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
上传代码(与html表单位于同一文件,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>
我的输出是:
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
文件的权限和信息:
[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
【问题讨论】:
-
什么是
$files..??? -
缺少变量名的_和区分大小写? $files !== $_FILES
-
愚蠢的我,解决了调试输出问题。现在我对整个事情的原始问题是永远不会创建文件(意思是,PHP 或其他任何东西)无法获取文件。
-
您的代码中缺少某些内容。行动是
./而不是upload.php。也许您只是将文件从/tmp/移动到/home/torxed/? -
使用
move_uploaded_file时,即使对于大文件也很快,因为它只是更改文件的地址而不是其内容。该文件没有被复制,它被移动了。如果你不使用上传的临时文件,它就消失了,这就是临时的!
标签: php html linux file-upload