Forum Moderators: coopster

Message Too Old, No Replies

Reading img file from ISAPI .dll URI

How-to guide line needed!

         

urkeystore

12:08 am on Jan 29, 2004 (gmt 0)

10+ Year Member



Advice or references to information appreciated...

I would like to capture an image file that results from a URI ending with a .dll extension. I assume the .dll conforms to ISAPI but I don't know much about that yet. The big picture is that I want to capture a third party dynamically generated image (chart) normally displayed in a webpage and cache it on a PHP based server as a static image file (.gif, jpeg, or other).

Any suggestions or references to discussions of this would be appreciated. I'm new to PHP but with a long history of C/C++ and Java coding. Thanks!

coopster

9:52 pm on Jan 29, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, urkeystore!

If it is a chart displayed in a web page, why not just open the remote URI and read the file, parsing out the image?

urkeystore

2:40 am on Jan 30, 2004 (gmt 0)

10+ Year Member



Thank you for the welcome Coopster. I don't know how I've gone as long as I have without running into WebmasterWorld.

I was making the problem harder than it is - thanks for your comments. I found this code below and it looks pretty much like what I'm wanting to do.

<?
if (!file_exists("files/".$HTTP_GET_VARS[id].".jpg")){
$rhost="http://www.yourremotehost.com";
$fp1 = fopen($rhost."/images/image.php?id=".$HTTP_GET_VARS[id],"r");
$fp2 = fopen("files/".$HTTP_GET_VARS[id].".jpg","w");
while(!feof($fp1)) {
$line = fgets($fp1, 1024);
fputs($fp2,$line,strlen($line));
}
fclose($fp1);
fclose($fp2);
}
$fp=fopen("files/".$HTTP_GET_VARS[id].".jpg","r");
$contents = fread ($fp, filesize("files/".$HTTP_GET_VARS[id].".jpg"));
fclose($fp);

header("Content-Type: image/jpeg");
header("Content-Disposition: inline");
echo $contents;
?>

coopster

1:15 pm on Jan 30, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Bingo. Looks like that should work. If you have any trouble tweaking it to your needs just come back here to WebmasterWorld. It is a very good forum.

I was making the problem harder than it is...

We've all been there. Then we come here! As the Proverb states:

for waging war you need guidance, and for victory many advisers.

urkeystore

11:14 pm on Jan 30, 2004 (gmt 0)

10+ Year Member



Thanks again Coopster!

urkeystore

3:22 am on Feb 14, 2004 (gmt 0)

10+ Year Member



For the record, that code I have above didn't work with binary image files. The transfer size was always a fraction of the original file - some character in the files was considered EOF I assume. May be due to an older release of PHP, don't know. I used the slower binary supported fgetc() and fwrite() as follows:

while (false == feof($fp1)) {
$char = fgetc($fp1);
fwrite($fp2,$char);
}

coopster

3:09 pm on Feb 14, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Cool, good for you.

There are a few things I can think of off the top of my head that may have been reasons that your original code did not worked as you expected.

First, as you stated, it may be your version of PHP. PHP <= 4.2 is different than PHP >= 4.3. Espcecially when it comes to file read

length
and binary-safe file read.

Second, it may be the file size specified (or by default) in your file reads. It's the last parameter for each of the fgetc, fgets, and fread functions.

And last, it may be related to the warnings in the PHP manual regarding binary file reading, especially on Windows platforms:


On systems which differentiate between binary and text files (i.e. Windows) the file must be opened with 'b' included in fopen() [php.net] mode parameter.

$handle = fopen($filename, "rb");

Just some afterthoughts. Congrats on the legwork and getting it going, urkeystore!