首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >physically,['tmp_name']物理上不存在

physically,['tmp_name']物理上不存在
EN

Stack Overflow用户
提问于 2013-09-26 09:46:33
回答 3查看 2.7K关注 0票数 3

这是一些非常基本的东西。由于一个未知的原因,我不能通过标准的HTML+PHP上传表单上传文件。

该文件在/tmp下本地不存在

php.ini

代码语言:javascript
复制
;;;;;;;;;;;;;;;;
; 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位于同一个文件中)

代码语言:javascript
复制
print '<pre>';
print var_dump($_FILES);
print var_dump(is_uploaded_file($_FILES["file"]["tmp_name"]));
print is_writable('/tmp');
print '</pre>';

html

代码语言:javascript
复制
<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>

我的产出是:

代码语言:javascript
复制
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

有关文件的权限和信息:

代码语言:javascript
复制
[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
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-09-26 10:13:43

我自己解决了。尽管这个问题很愚蠢,但答案却更加愚蠢。

代码语言:javascript
复制
[torxed@archie http]$ ls -lh /srv/http | grep tmp
drwxr-xr-x 2 torxed root 4.0K Sep 26 14:10 tmp

我假设该文件在/tmp下存在的时间足够长,足以让我看到它是被创建的,这在一开始是很愚蠢的。

但是,尝试使用move_uploaded_file返回的false时,试图将其移动到./中,这是因为对文件夹的权限是错误的。

move_uploaded_file($src, '/srv/http' + $src);只需将其移动到另一个临时位置即可工作(在修复/srv/http/tmp上的写权限之后)

票数 3
EN

Stack Overflow用户

发布于 2013-09-26 09:56:46

您是否将post_max_size值设置为更高的值?

票数 1
EN

Stack Overflow用户

发布于 2013-09-26 09:55:00

代码语言:javascript
复制
var_dump(is_uploaded_file($_FILES["file"]["tmp_name"]));
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19024822

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档