You are here: Re: Try to get a file from a server by PHP « PHP Programming Language « IT news, forums, messages
Re: Try to get a file from a server by PHP

Posted by Jamie Davison on 10/21/05 19:20

On 10/21/05 11:00 AM, in article
1129906853.363829.103040@g47g2000cwa.googlegroups.com, "NurAzije"
<nurazije@gmail.com> wrote:

> I am trying to make afunction to get information from one file and
> print it or put it in an array, the problem in headers I can't figure
> that it is giving me this:
> ********
> HTTP/1.1 400 Bad Request Date: Fri, 21 Oct 2005 14:48:06 GMT Server:
> Apache Connection: close Content-Type: text/html; charset=iso-8859-1
> Bad Request
> Your browser sent a request that this server could not understand.
>
> Request header field is missing colon separator.
>
> Host=www.imtec.ba
> ********
> My code is :
> *********
> <?
> function getFile($host,$file)
> {
> $request="GET $file HTTP/1.0\r\n"; // This is the path part of the
> link
> $request.="Host=$host\r\n\r\n"; // This is the server part of the
> link
>
> // Now let's try connecting:
> $fp=fsockopen($host, 80, $errno, $errstr, 30);
>
> // Let's see if we made it
> if (!$fp)
> {
> return(false);
> }
> else
> {
> // If we made it, let's send the request:
> fputs($fp, $request);
>
> while (!feof($fp))
> {
> $response.=fgets($fp, 128);
> }
> fclose($fp);
> return($response);
> }
> }
> echo getFile("www.imtec.ba","index.php");
> ?>
> *********
> Any help, what is wrong..
> Thank you
>


I would suggest using CURL whenever possible . .

If you have CURL compiled into your PHP distribution . . .

The folowing pulled from http://us3.php.net/curl

<?php

$ch = curl_init("http://www.imtec.ba/");
$fp = fopen("imtect.txt", "w");

curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);
curl_close($ch);
fclose($fp);
?>


If not . . .

<?php

$host = http://www.imtec.ba;
$curl_cmd = '/your/path/to/curl '. $host;
$imtec_file = exec($curl_cmd);


. . . Save it
?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация