Greetings list!
Say I want to copy a jpg from a remote server onto mine, using PHP.
Right now, my script opens a socket to the remote server, and opens the
image file. It copies its contents into a dummy variable, opens a new
file on my server, and dumps the contents of the dummy variable into the
new file.
For reasons I cannot figure out, it is not working the way I want.
Rather than display the image, I get an nothing when opening it in an
image viewer.
Code follows:
------
<?php
$ip = '10.10.10.3';
$port = '80';
$h = @fsockopen($ip, $port, $err, $str, 5);
if ($h)
{
// Get current image
$h = @fsockopen($ip, $port, $err, $str, 5);
$out = "GET /record/current.jpg HTTP/1.1\r\n";
$out .= "Host: $ip\r\n";
$out .= "Connection: Close\r\n\r\n";
fputs($h, $out, strlen($out));
$data = '';
while (!feof($h))
{
$data .= fgets($h, 128);
}
fclose($h);
// Store to file
$f = fopen('/path/test.jpg', "wb");
if ($f)
{
fwrite($f, $data, strlen($data));
fclose($f);
}
else
{
die('cannot open file for writing');
}
}
else
{
die('cannot contact server');
}
?>
---------
I have trimmed the code some, and omitted the part where I remove the
HTTP headers and other information I do not need.
Why isn't this working for me?
Thanks in advance,
Jay
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php