简体   繁体   English

无法使用 Php 上传照片

[英]Cant Upload Photos Using Php

I'm trying to upload a photo to mysql database using php, however I'm getting the following error:我正在尝试使用 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'

Here is my code:这是我的代码:

$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;
        }
    }

Looks like you're dealing with some permissions issue where your application server doesn't have permission to move the images from their current folder /Applications/XAMPP/xamppfiles/temp/ .看起来您正在处理一些权限问题,您的应用程序服务器无权从当前文件夹/Applications/XAMPP/xamppfiles/temp/中移动图像。

Can you change the permissions of the folder to see if that fixes the issue?您可以更改文件夹的权限以查看是否可以解决问题吗?

Run the command bellow:运行以下命令:

chmod 777 /Applications/XAMPP/xamppfiles/temp/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM