开发者

PHP imagecreatefrompng(file) fails when file is a dynamic image file?

开发者 https://www.devze.com 2023-02-07 22:29 出处:网络
Is it possible to use imagecreatefrompng() with a php file that returns a dynamic png image? eg. <?php

Is it possible to use imagecreatefrompng() with a php file that returns a dynamic png image?

eg.

<?php
 $IM = imagecreatefrompng('image.php?var=1');
?>

where image.php looks something like:

开发者_StackOverflow中文版
<?php
 // code to generate image
 header("content-type: image/png");
 imagepng ( $OUTPUT );
?>

At the moment I'm getting a "failed to open stream" error - can this be done? If not, are there any quick & easy workarounds? (that don't involve using image.php to save a .png file for the script to detect instead.)

Thanks,

Chris


Query parameters ?var=1 work only when requesting a resource through http, not through the file system. To do this, you would have to specify a full URL:

<?php
 $IM = imagecreatefrompng('http://localhost/image.php?var=1');
?>

(If your PHP is configured to allow this)

However, the usually much more desirable way would be to include image.php directly and pass var to it using a normal variable. That saves you a http request that, even if made locally, spawns a new PHP process.

0

精彩评论

暂无评论...
验证码 换一张
取 消