我想使用函数move_uploaded_file()
使用PHP上传图像。move_uploaded_file()使用临时主机帐户域
PHP
// Get image variables
$file = $_FILES['image']['tmp_name'];
$path = "images/products/large/";
$image_hash = "ty1bi"; // This would be generated
//I have also tried this: $path = "home/the_user/public_html/images/products/large/";
//$_SERVER['DOCUMENT_ROOT'] is equal to home/root_user/public_html/
// Upload image
if(!move_uploaded_file($file, $path . $image_hash . ".jpg")) {
header("location:admin/add.php?e=1");
exit;
}
目前,我得到:
警告:move_uploaded_file(住宅/ root_user /的public_html /图像/产品/大/ ty1bi.jpg) [ function.move-uploaded-file]:未能打开流: /home/root_user/public_html/includes/functions.php on line 63没有这样的文件或目录
警告:move_uploaded_file()[function.move-uploaded-file]:无法将 '/ tmp/phpJSKsYA'移动到'home/root_user/public_html/images/products/large/ty1bi.jpg' in/home/root_user/public_html/includes/functions.php on line 63
主机帐户在WHM中建立,我通过/~the_user/
目录访问网站。所以站点名称可以是主/主机域名或服务器IP地址,然后是/~the_user
。
由于错误显示/root_user
这将是WHM主机的用户名,我不认为它能够访问/~the_user
。我试图更改$path
中的文档根目录,因此它从home/
开始,包括/the_user
,但我也没有运气。
有没有办法做到这一点,或者我必须使用/测试这个域名?
UPDATE
由于文档根是根用户名下方,这是存在的问题是绝对路径的正确版本。通过构建路径,我正朝着正确的方向迈进,但这绝对是由于路径字符串开始时缺少斜线。
这行代码帮助解决了该问题:
$path = "/home/the_user/public_html/images/products/large/";
你肯定有'图像/产品/大/ ...'目录下,其中这个脚本执行? – 2013-03-08 21:08:19
是的。绝对确定。 – 2013-03-08 21:10:04
可能值得一提的是这个脚本是在'/ includes/functions.php'中触发的,但是如果我引用文档根目录,这应该不会有问题吗? – 2013-03-08 21:10:52