用php尝试上传文件,遇到了点有关问题

WBOY
Release: 2016-06-13 13:39:07
Original
938 people have browsed it

用php尝试上传文件,遇到了点问题
按照网上的例子写的php code应该是没什么问题的:

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
Copy after login
file upload:

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->


Copy after login

输出是
Array ( [userfile] => Array ( [name] => 未命名.jpg [type] => image/pjpeg [tmp_name] => /tmp/phpdruvC1 [error] => 0 [size] => 1059 ) ) Warning: move_uploaded_file(uploads/未命名.jpg): failed to open stream: Permission denied in /disks/diskh/zco/maql2/public_html/test/test/demo2.php on line 8 Call Stack: 0.0001 329800 1. {main}() /disks/diskh/zco/maql2/public_html/test/test/demo2.php:0 0.0001 329888 2. move_uploaded_file() /disks/diskh/zco/maql2/public_html/test/test/demo2.php:8 Warning: move_uploaded_file(): Unable to move '/tmp/phpdruvC1' to 'uploads/未命名.jpg' in /disks/diskh/zco/maql2/public_html/test/test/demo2.php on line 8 Call Stack: 0.0001 329800 1. {main}() /disks/diskh/zco/maql2/public_html/test/test/demo2.php:0 0.0001 329888 2. move_uploaded_file() /disks/diskh/zco/maql2/public_html/test/test/demo2.php:8 

很明显是move_uploaded_file移动不了图片,无法打开流?

因为学校是用WinSCP,所以都是把文件放在学校的服务器里面
我觉得这是没法上传的原因,有人知道如何解决吗

------解决方案--------------------
文件权限检查了吗,
------解决方案--------------------
文件路径看下
------解决方案--------------------
/disks/diskh/zco/maql2/public_html/test/test/uploads 目录不存在或不可写
文件系统不支持中文名
------解决方案--------------------
Permission denied in 

没有访问权限 或者写入权限 甚至可能不存在你访问的位置
------解决方案--------------------
Warning: move_uploaded_file(uploads/test1.jpg): failed to open stream: 


重点检查路径问题,确定可写及存在,,,此函数不会帮你创建目录

如果文件被包含执行的,,,建议你用绝对路径
------解决方案--------------------
既然上传过来有图片信息,那就是这块你处理的有问题了,第一,需要确认所有目录是否存在,move_uploaded_file(),不能创建目录,第二,查看一下你上传的路径是否正确 ,第三,查看一下你的文件权限是否足够。再者他们是不是同一台服务器,等之类的问题。
------解决方案--------------------
文件路径问题
------解决方案--------------------
文件路径问题
------解决方案--------------------
 
$folder=$_SERVER["DOCUMENT_ROOT"]."/uploads/";//前提是你的站点根目录下必须有uploads文件夹哦
chmod($folder,0777);

if(is_uploaded_file($_FILES['userfile']['tmp_name'])){

move_uploaded_file($_FILES['userfile']['tmp_name'],$folder.$_FILES['userfile']['name']);
}else{
echo'cannot find file';
}

?>
------解决方案--------------------
把所有的错误提示都打开,看报啥错
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template