即使在将权限更改为777并且在我的代码输出中显示图像已上载后,图像仍未在digitalocean上的ubuntu服务器中使用PHP上载?以前,它显示未授予权限,因此我使用chmod 777 ./Images
更改了此目录的权限。
<?php
require_once '../config.php';
require_once '../function2.php';
if ($_SERVER['REQUEST_METHOD']=="POST") {
/*foreach($_POST as $key => $value) {
$params[$key] = $value;
}*/
$isImage = isset($_FILES['imgUrl']['tmp_name']);
if ($isImage) {
$upload_dir ="../Images/";
echo "upload_dir: " . $upload_dir . "<br>";
if (file_exists($upload_dir)) {
if (is_writable($upload_dir)) {
$target = $upload_dir; //"dirname(__FILE__)" . "photos/";
$target = $target . 'Visnu.png';
$moved = move_uploaded_file($_FILES['imgUrl']['name'], "$target");
echo "isMoved: " . $moved;
} else {
echo 'Upload directory is not writable<br>';
}
} else {
echo 'Upload directory does not exist.<br>';
}
echo $target . "<br>";
// echo dirname(__FILE__)."<br>";
echo "Upload: " . $_FILES["imgUrl"]["name"] . "<br>";
echo "Type: " . $_FILES["imgUrl"]["type"] . "<br>";
echo "Size: " . ($_FILES["imgUrl"]["size"] / 1024) . " kB<br>";
echo "Stored in: " . $_FILES["imgUrl"]["tmp_name"];
}
/*$url = $config['URLS']['API_PATH'] . $config['URLS']['ADD_USER_FORM'];
echo $url;
echo json_encode($params);
$str = sendPostRequestWithImage($url, $params);
echo "res: " . $str;
$res = json_encode($str);
if ($res['status']=='ok') {
//header("location: ../signup-msg.php?success=0");
}
else {
//header("location: ../signup-msg.php?success=1");
}*/
}
else {
header('location: ../404.php');
}
?>
发布于 2018-07-02 04:34:13
在你的代码中,你有:
$moved = move_uploaded_file($_FILES['imgUrl']['name'], "$target");
密钥必须是tmp_name
而不是name
name
是用户pc上原始文件的密钥。tmp_name
是服务器上文件的(临时)名称
https://stackoverflow.com/questions/51126678
复制相似问题