HTML上传文件目录不存在

时间:2014-02-16 02:17:50

标签: php html

我正在尝试使用HTML表单和php上传文件,代码如下:

$targetPictureLocation = "/files/images/team/" . strtolower(str_replace(" ","", $_POST['name'])) . ".png";
move_uploaded_file($_FILES['file']['tmp_name'], $targetPictureLocation);

现在我相信 $targetPictureLocation 引用www.domain.com/targetpath/,因为文件前面有一个斜杠。这是对的吗?如果是这样,那么该目录确实存在,但是我收到了这些错误:

Warning: move_uploaded_file(/files/images/team/foobar.png) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/content/08/11798508/html/domainname/files/scripts/userManagement.php on line 259

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpwzO4X7' to '/files/images/team/foobar.png' in /home/content/08/11798508/html/domainname/files/scripts/userManagement.php on line 259

我做错了什么?

非常感谢

1 个答案:

答案 0 :(得分:1)

尝试:

$targetPictureLocation = $_SERVER['DOCUMENT_ROOT']."/domainname/files/images/team/" . strtolower(str_replace(" ","", $_POST['name'])) . ".png";`

您只是添加将PHP指向的相对路径:

  

/家庭/内容/ 08/11798508 / HTML /域名/文件/脚本/文件/图片/团队/

这是错误的位置。 PHP $_SERVER['DOCUMENT_ROOT']将返回脚本的基本目录网址。由于您要上传的文件夹位于父文件夹中。您应该使用$_SERVER['DOCUMENT_ROOT'],地址变为:

  

/家庭/内容/ 08/11798508 / HTML /域名/文件/图片/团队/