【问题标题】:try to upload image on a web page using this code, it keep giving error尝试使用此代码在网页上上传图像,它不断给出错误
【发布时间】:2020-03-13 02:10:49
【问题描述】:
    <?php
if (isset($_FILES['file'])) {
    $file_name = $_FILES['file']['name'];
    $file_tmp = $_FILES['file']['tmp_name'];
    $upload_folder = "images/";

    $move_file = move_uploaded_file($file_tmp, "$upload_folder/$file_name");

    if ($move_file) {
        echo "The file has been uploaded.";
    } else {
        echo "Sorry, there was an error uploading your file.";
    }
}
?>
<!DOCTYPE html>
<html>
<body>

    <form method="post" enctype="multipart/form-data">
        Select image to upload:
        <input type="file" name="file" id="file">
        <input type="submit" value="Upload Image" name="submit">
    </form>

</body>
</html>

这是欧元 警告:move_uploaded_file(images//489452.jpg):无法打开流:第 7 行 /Applications/XAMPP/xamppfiles/htdocs/ncs_project/test.php 中的权限被拒绝

警告:move_uploaded_file(): Unable to move '/Applications/XAMPP/xamppfiles/temp/php5kvoOW' to 'images//489452.jpg' in /Applications/XAMPP/xamppfiles/htdocs/ncs_project/test.php on line 7

【问题讨论】:

标签: php html


【解决方案1】:

更改图片文件夹的读写权限

【讨论】:

    【解决方案2】:

    使用此代码上传您的图片,它会在上传图片之前创建具有读写权限的文件夹:

    
                    if(!File::isDirectory($path)){
                        File::makeDirectory($path, 0777, true, true);
                    }
                    $image_path = Storage::disk('public')->put('iamges', $request->file('file'));
    
    

    【讨论】:

      猜你喜欢
      • 2022-07-21
      • 2023-02-24
      • 1970-01-01
      • 2021-05-13
      • 1970-01-01
      • 2021-06-23
      • 1970-01-01
      • 1970-01-01
      • 2012-03-09
      相关资源
      最近更新 更多