imagecreatefrompng() failed to open stream: HTTP request failed

一个人想着一个人 提交于 2019-12-11 15:37:19

问题


On my local host this code works well:

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

But when I use the same code in the server

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

I got the folloowing error:

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

How do I solve this?


回答1:


If the file is on your server, use a (relative) system path, not an url: E.g.:

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



回答2:


Before using imagecreate, can you download remote image into a local folder then work on it ?!

your ex:

$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');



回答3:


403 Forbidden means that the server blocked you from accessing the file. you can try doing a file_get_contents("http://...."); do get an error message, maybe the creator's of the site put one in place else you have to talk to them.



来源:https://stackoverflow.com/questions/7454695/imagecreatefrompng-failed-to-open-stream-http-request-failed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!