2011-09-17 101 views
0

在我的本地主机此代码工作得很好:imagecreatefrompng()未能打开流:HTTP请求失败

$im = imagecreatefrompng('BBcode.png'); 

但是,当我在服务器

$im = imagecreatefrompng('http://lazertag.elitno.net/drupal/BBcode.png'); 

使用相同的代码,我得到了以下错误:

Warning: imagecreatefrompng(http://lazertag.elitno.net/drupal/BBcode.png) [function.imagecreatefrompng]: failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in /www/elitno.net/l/a/lazertag/home/site/drupal/renderImage.php on line 46

我该如何解决这个问题?

+2

'HTTP请求失败! HTTP/1.1 403 Forbidden'很清楚,不是吗? –

回答

2

如果文件服务器上,使用一个(相对)系统路径,而不是一个网址: 例如为:

$im = imagecreatefrompng('drupal/BBcode.png'); 
0

使用imagecreate之前,您可以将远程图像下载到本地文件夹然后工作?

你的前任:

$imagefile = file_get_contents('http://lazertag.elitno.net/drupal/BBcode.png'); 
$fp = fopen('./BBcode.png', 'w+')); 
fputs($fp, $imagefile); 
fclo$fp); 
unset($imagefile); 
$im = imagecreatefrompng('./BBcode.png'); 
+0

你在'fclose(...)'行缺少字母 – scessor

+0

这将很难解决403禁止错误的问题 –

+0

这是我的服务器,我想要使用的文件已经存储在我的服务器上。 – Alex

0

403禁止意味着服务器访问该文件阻止你。你可以尝试做一个file_get_contents(“http:// ....”);确实收到错误信息,也许网站的创建者将其中一个放置在其他位置,否则您必须与他们交谈。

相关问题