Home  >  Article  >  Backend Development  >  PHP中文件上传的一个问题_PHP

PHP中文件上传的一个问题_PHP

WBOY
WBOYOriginal
2016-06-01 12:17:30703browse

我也一直很困惑。在文档上,说的比较模糊,就是 move_uploaded_file 这个函数,加了一步检查,检查这个文件是否是有 HTTP POST 上传的,


至于,如何检查的没有说。


我google 了好一阵子,都没有能解决这个问题,也不知道问题出现在哪里。后来,终于决定看源代码。终于在 源代码里面看到 把文件名 和


php 配置中的 upload_tmp_dir 这个参数进行比较,如果文件在这个目录下面,那么 move_uploaded_file 才会进行移动操作。而且这个比较是大小写敏感,/ \ 在Windows 下面也是不一样的。而在PHP配置文件解析的时候,会调用一个realpath 函数,也就是是说,你在move_uploaded_file 之前,


必须对$file['tmp_name'] = realpath($file['tmp_name']); realpath 一下。


还有一种情况,大家要注意,就是 move_uploaded_file 如果配置成一个无法访问的路径,那么你不管怎么处理,move_uploaded_file 总是不能成功移动文件。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn