move_uploaded_file()以不工作 [英] move_uploaded_file() not working

查看:216
本文介绍了move_uploaded_file()以不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写在PHP脚本在服务器上的文件上传。而code是继..

I am writing a script in php for the file upload on the server. And the code is following..

$target_path = "uploaded_images/";
$target_path = $target_path . basename( $_FILES['image']['name']); 
if(move_uploaded_file($_FILES['image']['tmp_name'], $target_path)) {

  echo "The file ".  basename( $_FILES['image']['name']). 
        " has been uploaded";
  } else{
  echo "There was an error uploading the file, please try again!";
}

但功能move_uploaded_file()以不工作,它提供了以下错误。

But the function move_uploaded_file() is not working and it gives the following error..

Warning: move_uploaded_file(uploaded_images/Mordent.jpg) [function.move-uploaded-file]:  failed to open stream: Permission denied 


Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpOWVz7o' to 'uploaded_images/Mordent.jpg'

我已经检查的所有permisions中的文件夹,甚至在php.ini中的安全模式是关闭的。

I have checked all the permisions to the folders and even the safe mode in php.ini is off.

请帮我出我需要这个亟待完成。

Please help me out I need this to be urgently done.

推荐答案

不要使用相对路径( uploaded_images / Mordent.jpg )在这里。它并不总是显而易见的是什么PHP的工作目录(它会使用转向相对路径为绝对的)的。

Don't use a relative pathname (uploaded_images/Mordent.jpg) here. It's not always obvious what PHP's working directory (which it will use to turn a relative path into an absolute one) is.

如果你想将图像移动到该目录是在相同的目录中的脚本,定义 $ target_path 这样的:

If the directory you're trying to move the images to is in the same directory as your script, define $target_path like:

$target_path = __DIR__ . '/uploaded_images/';

__ DIR __ 部分给你的绝对路径到你当前脚本所在的目录,那么你就追加了相对的一部分来表示。

The __DIR__ part gives you the absolute path to the directory your current script is in, then you append the "relative" part to that.

这篇关于move_uploaded_file()以不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆