$target_path = "/public_html/user_images/";
//$target_path = realpath(user_images(getcwd()))
$targetpath = basename( $_FILES['uploadedfile']['name']);
$target_path = $target_path . $targetpath;
move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path);
//echo "Image". basename( $_FILES['uploadedfile']['name']). " has been successfully uploaded.";
$user_img = $target_path;
前导/
斜线将一直带到服务器的根目录。您需要使用完整路径(在您的服务器上可能是例如/home/yourdomain.com/public_html/images/
,或者其他与您正在运行的脚本相关的路径,例如,如果您的上传脚本在./public_html/codes/
中,则为'../images/'
,如果脚本在./public_html/
中,则仅为'./images/
。
- 您还需要确保文件夹具有正确的写入权限
将错误报告添加到文件顶部,这将有助于查找错误。
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// rest of your code
旁注:错误报告只能在临时阶段进行,而不能在生产阶段进行。