我在服务器上上传文件的脚本有这个问题,该文件称为view.php。服务器不是本地主机,但由于 sudo,我拥有所有权限。我已经授予了该文件的所有权限(777)以及他应该上传文件的目录(称为uploads /)。我知道这不是一个好习惯,但我真的把一切都捆绑了!view.php 和文件夹 uploads/ 在同一个文件夹中,我不明白这里有什么问题,我是否必须更改路径(原始路径:/var/www/html/concrete5/application/blocks/insert,两者都在名为插入的文件夹中)?希望有人可以帮助我,在此先感谢!
这是我的代码 php:
$target_dir = "uploads/";
$target_file = $target_dir. basename($_FILE["fileToUpload"]["name"]);
$uploadOk=1;
$imageFileType=strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
if($uploadOk == 0){
echo "Sorry, your file was not uploaded.";
}else{
if(move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)){ //--- the problem is here!
echo "The file ".htmlspecialchars(basename($_FILES["fileToUpload"]["tmp_name"])). " has been uploaded.";
}else{
echo "Sorry, there was an error uploading your file";
}
}