我正在嘗試使用 php 將照片上傳到 mysql 數據庫,但是出現以下錯誤: failed to open stream: Permission denied in '/The location of my php file' on line 40. move_uploaded_file(): Unable to move '/Applications/XAMPP/xamppfiles/temp/phpgZi5gV to 'The location where the image will be stored'這是我的代碼:$dir = $path;$default = "default.png";// get Filename$filename = basename($filen['name']);$targetFilePath = $dir.$filename;$filetype = pathinfo($targetFilePath, PATHINFO_EXTENSION);if(!empty($filename)) { //allowed file formats $allowedFormats = array("jpg", "png", "jpeg", "gif", "pdf"); if(in_array($filetype, $allowedFormats)) { if(move_uploaded_file($filen['tmp_name'], $targetFilePath)) { return $targetFilePath; } }
1 回答

滄海一幻覺
TA貢獻1824條經驗 獲得超5個贊
看起來您正在處理一些權限問題,您的應用程序服務器沒有權限將圖像從其當前文件夾中移動/Applications/XAMPP/xamppfiles/temp/
。
您能否更改文件夾的權限以查看是否可以解決問題?
運行以下命令:
chmod 777 /Applications/XAMPP/xamppfiles/temp/
- 1 回答
- 0 關注
- 127 瀏覽
添加回答
舉報
0/150
提交
取消