我正在尝试使用 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;
}
}
沧海一幻觉