无法使用Php上传照片

无法使用Php上传照片,php,file-upload,Php,File Upload,我试图使用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 sto

我试图使用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/

您确认该文件夹现在具有777权限了吗?从应用程序文件夹向上运行ll-lt one目录并显示输出抱歉,我的意思是确认临时文件夹有rwxrwx、cd到/applications/XAMPP/xamppfiles,然后运行ll-lt并显示输出无法直接在注释上上载图像。在这种情况下,apache服务器似乎没有访问该文件夹的权限,因为它属于用户守护进程,所以需要使用chown命令将该文件夹的所有者更改为运行apache进程的同一用户。因此,首先运行这个ps aux | egrep'(apache | httpd)来获取apache进程的用户名,然后运行sudo chown-R您找到的用户名:usernameyoufound/Applications/XAMPP/xamppfiles/temp/显然将chown命令中的两个“usernameyoufound”替换为拥有apache进程的任何东西