PHP   发布时间:2022-04-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了PHP-文件上传,[‘tmp_name’]在物理上不存在大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

这是一些非常基本的东西.
出于未知原因,我无法通过标准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

解决方法:

我自己解决了.
问题很愚蠢,答案甚至更愚蠢.

[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.
原因是文件夹的权限错误.

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

大佬总结

以上是大佬教程为你收集整理的PHP-文件上传,[‘tmp_name’]在物理上不存在全部内容,希望文章能够帮你解决PHP-文件上传,[‘tmp_name’]在物理上不存在所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: