我正在尝试制作图片上传器。我在网上搜索过,但没有找到合适的答案。当我调用move_uploaded_file时,它总是抛出错误。它说源路径有base_dir限制,尽管文档说:
但是,仅限于目标路径的限制 允许移动文件名可能与之冲突的上传文件 这样的限制。
代码:
$extension = pathinfo($_FILES['uploader']['name'], PATHINFO_EXTENSION);
if ($extension != "jpg" && $extension != "png" && $extension != "gif")
throw new RuntimeException("Unsupported format! Supported formats are jpg, png, gif.");
$filepath = "/home/iv0113/public_html/data/uploads/images/" . md5($_FILES['uploader']['tmp_name']) . "." . $extension;
if (!move_uploaded_file($_FILES['uploader']['tmp_name'], $filepath))
throw new RuntimeException("Error uploading file!");
错误:
Warning: move_uploaded_file(): open_basedir restriction in effect. File(/tmp/phpaG1OIW) is not within the allowed path(s): (/home/iv0113/) in /hd2/home/iv0113/public_html/php/photos_functions.php on line 44
Warning: move_uploaded_file(): open_basedir restriction in effect. File(/tmp/phpaG1OIW) is not within the allowed path(s): (/home/iv0113/) in /hd2/home/iv0113/public_html/php/photos_functions.php on line 44
Warning: move_uploaded_file(/tmp/phpaG1OIW): failed to open stream: Operation not permitted in /hd2/home/iv0113/public_html/php/photos_functions.php on line 44
Warning: move_uploaded_file(): Unable to move '/tmp/phpaG1OIW' to '/home/iv0113/public_html/data/uploads/images/7a2b480c131000161369ca009260c0d4.jpg' in /hd2/home/iv0113/public_html/php/photos_functions.php on line 44
答案 0 :(得分:0)
问题是目标目录没有正确的权限。