PHP 在 allow_url_fopen 开启时获得 "Permission denied"
PHP getting "Permission denied" while allow_url_fopen is on
我将通过 php 从单个 url 加载图像。我用这个 file_put_contents
:
$url = 'http://www.example.com/test.jpg';
$img = 'C:\xampp\htdocs\myproject\assets';
file_put_contents($img, file_get_contents($url));
我的 php.ini
里也有这个:
allow_url_fopen=On
但是我得到这个错误:
Severity: Warning
Message: file_put_contents(C:\xampp\htdocs\trendkala\fereydoon\assets): failed to open stream: Permission denied
Filename: controllers/admin.php
Line Number: 55
Backtrace:
File: C:\xampp\htdocs\trendkala\fereydoon\application\controllers\admin.php
Line: 55
Function: file_put_contents
问题可能出在您写入内容的文件路径上。您需要在文件路径中添加文件名,使其成为完全限定路径。
类似于:
$img = 'C:\xampp\htdocs\myproject\assets\test.png';
还要确保您对该文件夹具有写入权限。
我将通过 php 从单个 url 加载图像。我用这个 file_put_contents
:
$url = 'http://www.example.com/test.jpg';
$img = 'C:\xampp\htdocs\myproject\assets';
file_put_contents($img, file_get_contents($url));
我的 php.ini
里也有这个:
allow_url_fopen=On
但是我得到这个错误:
Severity: Warning
Message: file_put_contents(C:\xampp\htdocs\trendkala\fereydoon\assets): failed to open stream: Permission denied
Filename: controllers/admin.php
Line Number: 55
Backtrace:
File: C:\xampp\htdocs\trendkala\fereydoon\application\controllers\admin.php
Line: 55
Function: file_put_contents
问题可能出在您写入内容的文件路径上。您需要在文件路径中添加文件名,使其成为完全限定路径。
类似于:
$img = 'C:\xampp\htdocs\myproject\assets\test.png';
还要确保您对该文件夹具有写入权限。