我正在尝试使用以下代码将文件上传到我的服务器:
$feedInstanceID = random_str(32,'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
$target_dir = "/home/mysite/public_html/content";
if(!file_exists($target_dir)) {
mkdir($target_dir, 0777, true);
}
if ($resourceType == "image") {
$my_file_name = $feedInstanceID . ".jpg";
}
else {
$my_file_name = $feedInstanceID . ".mov";
}
$target_dir = $target_dir . "/" . basename($_FILES["file"][$my_file_name]);
if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_dir))
{
if ($result) {
$response["error"] = FALSE;
echo json_encode($response);
}
else {
$response["error"] = TRUE;
$response["error_msg"] = "Can't insert!";
echo json_encode($response);
}
} else {
$response["error"] = TRUE;
$response["error_msg"] = $_FILES["file"]["error"];
echo json_encode($response);
}
我收到以下错误输出:
[25-Aug-2016 14:18:59 UTC] PHP Notice: Undefined index: RsmyqMeswmZZ4eo44X14D6bYEgPiobvV.jpg in /home/mysite/public_html/new_upload.php on line 81
[25-Aug-2016 14:18:59 UTC] PHP Warning: move_uploaded_file(): The second argument to copy() function cannot be a directory in /home/mysite/public_html/new_upload.php on line 83
[25-Aug-2016 14:18:59 UTC] PHP Warning: move_uploaded_file(): Unable to move '/tmp/phpKMPply' to '/home/mysite/public_html/content/' in /home/mysite/public_html/new_upload.php on line 83