如何在该代码中设置chmod 777?我在上传图片到服务器时遇到问题,你能帮我解决这个问题吗?

$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
$newfilename = time().end($temp).$_FILES["file"]["name"];

if(!empty($_FILES["file"]["name"])){
    if ((($_FILES["file"]["type"] == "image/gif")
    || ($_FILES["file"]["type"] == "image/jpeg")
    || ($_FILES["file"]["type"] == "image/jpg")
    || ($_FILES["file"]["type"] == "image/pjpeg")
    || ($_FILES["file"]["type"] == "image/x-png")
    || ($_FILES["file"]["type"] == "image/png"))
    && in_array($extension, $allowedExts))
    {


        $sql = "INSERT INTO `doctor-info` VALUES ('', '$licno', '$txtlname', '$fname', '$mname', '$address','$email' ,'$mobile', '$specialization','$twopecial','$threespecial','$fourspecial', '$newfilename')";
        mysql_query($sql);

        move_uploaded_file($_FILES["file"]["tmp_name"],"images/upload/" . $newfilename);

        echo "<script> alert('data save!'); </script>";
        $get_id =  mysql_insert_id();
        $sql2 = mysql_query("SELECT id FROM `doctor-info` WHERE id='$get_id'");
        $row=mysql_fetch_array($sql2);
        $id = $row['id'];

        echo "<script> window.location = 'doctor.php?action=edit&id=$id'</script>";
    }
    else{

        echo "<script> alert('Not an images!'); </script>";

    }
}

最佳答案

第一次设置上载文件夹的权限

if(!is_dir('/path/to/project/folder/images/upload/')){
     mkdir('/path/to/project/folder/images/upload/');
}
chmod('/path/to/project/folder/images/upload/',0777);

然后上传文件
move_uploaded_file($_FILES["file"]["tmp_name"],"images/upload/" . $newfilename);

您的图像文件不需要渲染权限

09-30 16:10
查看更多