权限否认与function.file看跌,内容警告

问题描述:

我使用此代码下载动态图像文件,这已经是我的服务器权限否认与function.file看跌,内容警告

$url = 'example.com/test/image.php'; 
$img = 'cert.png'; 
file_put_contents($img,'file_get_contents($url)); 

allow_url_fopen选项在服务器上已经启用的。但我还是发现了以下错误

Warning: file_put_contents(cert.png) [function.file-put-contents]: failed 
to open stream: Permission denied in D:/... on line 42 

我看到了同样的错误在其他网站上http://www.rsi-relief.com/rsi-links/ergonomics-information/ergoweb/

我是新来的PHP,所以我有点糊涂在这里。请帮助

+0

您是否有权写入文件?你需要给Apache的用户权限 – JohnP 2011-12-21 06:00:13

+0

我试过它通过FTP但失败了。你可以告诉我如何给这些权限或SM参考文章? – Anurag 2011-12-21 06:05:00

+0

老兄,你之前的问题已经因为本地化而关闭了。如果你想有更好的机会,你应该用更有意义的东西来编辑你的问题(例如包括你的FTP代码等) – ajreal 2011-12-21 06:25:07

这与我错误的php代码无关,但在您的服务器/主机上的文件系统权限。如果您通过SSH或FTP访问,则可以尝试修改文件夹/文件的cmod设置。

更新

你的代码是错误的,试试这个

// this is the path where you need write access on your server 
$imgDestinationPath = '/you/need/a/physical/serverpath/here/cert.png'; 
$url = 'http://example.com/test/image.php'; 
$content = file_get_contents($url); 
file_put_contents($imgDestinationPath, $content); 
+0

我已经试过了。但是每当我尝试更改权限时,它都会显示状态:\t将'/ httpdocs/test'的权限设置为'777' 命令:\t CWD/httpdocs 响应:\t 250 CWD命令成功。 命令:\t站点CHMOD 777测试 响应:\t 500'Site CHMOD 777 test':命令不明白 – Anurag 2011-12-21 06:01:30

+0

您尝试过'http://example.com'而不是'example.com? – Grrbrr404 2011-12-21 06:06:23

+0

是的先生..我做到了 – Anurag 2011-12-21 06:11:34

而是命令行的,我建议你尝试用FileZilla中或某些FTP客户端,右键单击目录,然后单击文件权限。然后选择适当的权限并点击确定。这应该工作