[英]Cant Upload Photos Using Php
我正在嘗試使用 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;
}
}
看起來您正在處理一些權限問題,您的應用程序服務器無權從當前文件夾/Applications/XAMPP/xamppfiles/temp/
中移動圖像。
您可以更改文件夾的權限以查看是否可以解決問題嗎?
運行以下命令:
chmod 777 /Applications/XAMPP/xamppfiles/temp/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.