首页 > 解决方案 > 在 macOS Catalina 中上传图像时出现以下错误

问题描述

当我所做的只是将文件上传到数据库中时,我的代码运行良好。但是当我尝试将它也存储在文件夹中时,我收到了警告:

move_uploaded_file(files/picture.jpg): 无法打开流: 权限被拒绝和 move_uploaded_file(): 无法将 '/Applications/XAMPP/xamppfiles/temp/phpB59AaC' 移动到 'files/picture.jpg

I'm also tried about permissions and echo the path and directory give me currently path
I think I'm missing something important but i cant figure out here is my codes:
  html code->>> 
    <form action="" enctype="multipart/form-data"  method="post">
            <input name="myfile" type="file">
            <button>
                go!
            </button>
        
        </form>
phpcode->>>
       <?php
        if (isset($_FILES['myfile'])){
        $file=$_FILES['myfile'];
        $fileName=$file['name'];
        $fileSize=$file['size'];
        $fileTmp=$file['tmp_name'];
        $fileType=$file['type'];
        $fileError=$file['error'];
        $uploadOk = 1;
        $target='files/';
        $newName='picture';
        if ($fileType != 'image/jpg' and $fileType != 'image/jpeg'){
        $uploadOk = 0;
        }
        if ($fileSize > 5242880){
            $uploadOk = 0;
        }
        if ($uploadOk == 1){
            $ext=pathinfo($fileName,PATHINFO_EXTENSION);
        
            $target=$target . $newName . '.' . $ext;
        
        
            move_uploaded_file($fileTmp, $target);
        }
        
        }
        ?>

标签: php

解决方案


可能是权限的问题。你可以尝试更改文件夹的权限,让每个人都可以读写。 试试这样


推荐阅读