file_put_contents(D:\ xampp \ htdocs \ toh-barcode \ public \ uploads \ barcode):无法打开流:权限被拒绝

时间:2017-10-13 07:22:46

标签: php laravel

我使用以下代码将其他网址中的图片保存到我的文件夹

<?php
  $string = "https://eandata.com/.../products/000/000/0000000000000.jpg";
  $img = public_path('uploads\barcode');
  file_put_contents($img, file_get_contents($string));
?

它报告错误:“file_put_contents(D:\ xampp \ htdocs \ toh-barcode \ public \ uploads \ barcode):无法打开流:拒绝权限。” 如何修复bug。谢谢大家

2 个答案:

答案 0 :(得分:0)

我的解决方案是通过转到文件夹&gt;来授予images文件夹的权限。右键单击&gt;属性并转到Permission,然后将所有权限更改为read&amp; write

答案 1 :(得分:0)

首先请更改为上传/条形码,而不是上传\条形码 然后请确保已创建路径上传/条形码。

$path = 'uploads/barcode';
if (!file_exists($path)) {
    mkdir('uploads/barcode');
}

如果仍然无法正常工作,请将发件人的权限更改为Read&amp;写:

Linux或Mac OS

chmod -R 777

WINDOWNS

Going to the Folder > Right click > properties and goes to Permission and then change all the permissions to Read & Write