I can get it to connect and it will show the data for the image but when i try to write it to a file it saves the header return as well.
I used to code alot but have been out of the game for awhile and I'm forgetting alot.
heres an example on my code:
Code: Select all
<?php
error_reporting(E_ALL);
$credentials = base64_encode("user:pass");
$service_port = getservbyname('www', 'tcp');
$address = gethostbyname('www.bla.com');
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket < 0) {
echo "socket_create() failed: reason: " . socket_strerror($socket) . "\n";
}
$result = socket_connect($socket, $address, $service_port);
if ($result < 0) {
echo "socket_connect() failed.\nReason: ($result) " . socket_strerror($result) . "\n";
}
$in = "GET /images/image.jpg HTTP/1.1\r\n";
$in .= "Authorization: Basic $credentials\r\n";
$in .= "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\r\n";
$in .= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4\r\n";
$in .= "Host: http://www.bla.com\r\n";
$in .= "Connection: Close\r\n\r\n";
$out = '';
socket_write($socket, $in, strlen($in));
while ($out = socket_read($socket, 2048)) {
$total .= $out;
}
socket_close($socket);
echo $total;
$fn = "pic.jpg";
$fh = fopen($fn, 'w') or die("can't open file");
fwrite($fh, $total);
fclose($fh);
?>