move_uploaded_file 无效

move_uploaded_file doesnt work

我正在尝试通过 PHP 脚本上传图片。

当我上传图片时,脚本中的所有条件都为真,但 move_uploaded_file 功能似乎不起作用。

可能是什么问题?

我的HTML密码是

<form id="register_form" action="" method="post" enctype="multipart/form-
data">
Select image to Upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>

PHP 脚本:

<?php
$target_dir = "/home/infibusiness1/Desktop/uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
    echo "File is an image - " . $check["mime"] . ".";
    $uploadOk = 1;
} else {
    echo "File is not an image.";
    $uploadOk = 0;
}
}

// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'], 
$target_file)) {
    echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has   
been uploaded.";
} else {
    echo "Sorry, there was an error uploading your file.";
echo "<br>File Name : ".$_FILES['fileToUpload']['tmp_name'];
}
}
?> 

确保网络服务器对目标目录有写权限? 您将需要知道 Web 服务器是哪个用户 运行,或者如果安全性不是问题,请尝试

chmod 777 /home/infibusiness1/Desktop/uploads/