我正在使用類似博客的網站進行編碼,并具有正確發布和顯示帖子的功能。目前,我正在嘗試通過使用PHPmove_uploaded_file函數將圖像上載到項目文件夾中的文件夾中,以添加一個將圖像包含在帖子中的選項。我已通過授予Apache用戶_www的讀取,寫入和執行權限chmod。我還確保了它有權在導致上載文件夾本身的父目錄中進行寫入,讀取和執行。我什至嘗試使用將項目文件夾的完全所有權轉讓給所述用戶chown。但是,我收到了一個PHP警告,內容為:PHP警告:move_uploaded_file(/ Users / MyUser / Desktop / Project / assets / php /../ uploads / 2.jpg):無法打開流:/ Users / MyUser / Desktop / Project / assets / php / upload中的權限被拒絕.php文件的PHP$target_dir = __DIR__ . "/../uploads/";var_dump($target_dir);$file = basename($_FILES["file"]["name"]);$target_file = $target_dir . $file;$allowed_extensions = array("jpeg", "jpg", "png");$imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));if(isset($_POST["upload"])) { echo $target_file; $stmt = $pdo->prepare("INSERT INTO images (imgTitle, imgLocation) VALUES (:imgTitle, :imgLocation)"); $stmt->execute(array( ":imgTitle" => basename($_FILES["file"]["name"]), ":imgLocation" => $target_file )); if ($imageFileType = in_array($imageFileType, $allowed_extensions)) { move_uploaded_file($_FILES["file"]["tmp_name"], $target_file); }}的HTML<form action="" method="post" enctype="multipart/form-data"> Select Image File to Upload: <p><input type="file" name="file"></p> <input type="submit" name="upload" value="Upload"></form>為什么會發生這種情況,如何在不將_www用戶更改為我的用戶的情況下解決此問題?
- 1 回答
- 0 關注
- 156 瀏覽
添加回答
舉報
0/150
提交
取消
