麻烦移动图片我想设置一些图片处理为我创建的网页,但我无法得到move_uploaded_file()正常工作...我不断收到这些错误:与move_uploaded_file()
Warning: move_uploaded_file(/htdocs/PHP/Pictures/picture.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /opt/lampp/htdocs/PHP/useredit.php on line 17
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpY0KKxH' to '/htdocs/PHP/Pictures/picture.jpg' in /opt/lampp/htdocs/PHP/useredit.php on line 17
我的代码如下所示:
if(isset($_FILES['image_file']))
{
$img_tmp_name = $_FILES['image_file']['name'];
$img_dir = "/htdocs/PHP/Pictures/";
$img_name = $img_dir . $img_tmp_name;
if(move_uploaded_file($_FILES['image_file']['tmp_name'],$img_name))
{
list($width,$height,$type,$attr) = getimagesize($img_name);
switch($type)
{
case 1:
$ext = ".gif";
break;
case 2:
$ext = ".jpg";
break;
case 3:
$ext = ".png";
break;
default:
echo "Image format not accepted";
}
$query = "UPDATE profile_pic SET img_path=$img_name WHERE uid='$uid'";
$img_id = mysql_insert_id();
$new_img_name = $img_dir . $img_id . $ext;
rename($img_name, $new_img_name);
}
}
if(mysql_query($query)or die('Error: ' . mysql_error()))
{
header("Refresh:0; url='control.php'");
}
文件夹PHP /图片存在。我该如何解决?
我怀疑'htdocs'是*根级别*文件夹。将该路径更改为相对于此脚本的目录。 – DCoder 2012-08-15 18:38:53
是的,像DCoder说的修复$ img_dir =“/ htdocs/PHP /图片/”;/htdocs应该在根级 – Skatox 2012-08-15 18:41:02
因此,如果lampp /同时包含tmp /和htdocs /我应该将目录更改为“../htdocs/PHP/Pictures”? – Psyberion 2012-08-15 19:19:15