Forum Moderators: coopster
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!
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;
?>
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.
while (false == feof($fp1)) {
$char = fgetc($fp1);
fwrite($fp2,$char);
}
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!