473,545 Members | 1,644 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Try to get a file from a server by PHP

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.=fget s($fp, 128);
}
fclose($fp);
return($respons e);
}
}
echo getFile("www.im tec.ba","index. php");
?>
*********
Any help, what is wrong..
Thank you

Oct 21 '05 #1
2 2362
On 10/21/05 11:00 AM, in article
11************* *********@g47g2 00...legr oups.com, "NurAzije"
<nu******@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.=fget s($fp, 128);
}
fclose($fp);
return($respons e);
}
}
echo getFile("www.im tec.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.t xt", "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
?>


Oct 21 '05 #2
"Jamie Davison" wrote:
I would suggest using CURL whenever possible . .


.... or just file_get_conten ts() <http://www.php.net/file_get_conten ts>

NurAzije: If it helps at all, the error you're getting is caused by this
line:
$request.="Host =$host\r\n\r\n"


Headers should be followed by a colon and a space, not an equals sign. So
maybe $request.="Host : $host\r\n\r\n" would have been a bit more successful.
But your code is still going to fall down flat if you receive a chunked
response, for example.

--
phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/
Oct 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
2448
by: CHIN | last post by:
Hi all.. here s my problem ( maybe some of you saw me on other groups, but i cant find the solution !! ) I have to upload a file to an external site, so, i made a .vbs file , that logins to the site, and then i have to select the file to upload.. i used sendkeys.. and i worked perfect.. BUT ... the computer must be locked for security (...
23
2880
by: Lamberti Fabrizio | last post by:
Hi all, I've to access to a network file from an asp pages. I've red a lot of things on old posts and on Microsoft article but I can't still solve my problem. I've got two server inside the same NT domain, each one has its own web server. The web server is always IIS 5.0.
1
2749
by: BW | last post by:
I am creating an upload/download function for an extranet site. Files will be uploaded to directory based upon the users login and associated project. The function works as long as I use "c:\Temp" as the directory. When I use any other hard coded directory or even Server.MapPath() the upload function fails and returns the error: "Exception has...
18
4323
by: Jen | last post by:
I'm using Microsoft's own VB.NET FTP Example: http://support.microsoft.com/default.aspx?scid=kb;en-us;832679 I can get the program to create directories, change directories, etc., but I can't get it to upload a file to the FTP server. I just get a "Cannot connect to remote server" error after this TRY: s = New...
8
9707
by: Sarah | last post by:
I need to access some data on a server. I can access it directly using UNC (i.e. \\ComputerName\ShareName\Path\FileName) or using a mapped network drive resource (S:\Path\FileName). Here is my problem: my vb.net program has problems with UNC. If the UNC server is restarted or goes off-line, my VB.net program crashes. The code for UNC...
4
4455
by: Matt Jensen | last post by:
Howdy I've got a rather strange issue occuring. I used forms based .NET authentication, although I'm also setting some session variables when people login. However, I've found when people use one of my webform pages which includes a button that pops up a window where you can upload files, if you upload files in this popup window, it...
9
2402
by: CGW | last post by:
I asked the question yesterday, but know better how to ask it, today: I'm trying to use the File.Copy method to copy a file from a client to server (.Net web app under IIS ). It looks to me that when I give a path like @"C:\holdfiles\myfile.txt" it looks on the server C drive. How do I pull from the client? Do I need a different class and/or...
1
6453
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting" setting to be "E_ALL", notices are still not getting reported. The perms on my file are 664, with owner root and group root. The php.ini file is located...
4
6884
by: Vlad | last post by:
I am having problems using the file.create method within a function that is called when looping through an array of filepaths. If I call my function with a hardcoded file path --C:\Temp.txt the function creates the file as expected. When I loop through my array I get the error - "ArgumentException was unhandled - Illegal characters in...
3
4406
by: premprakashbhati | last post by:
hi, good evening.. i am going to upload an image in a web form .....for that iam using HTML input(file) control and one web control button i.e., Upload_Button() here is the code ...its work fine when iam using a normal web page... but can't in content page.... Code in Master Page <%@ Master Language="C#" AutoEventWireup="true"...
0
7459
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7653
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7803
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7411
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7749
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5322
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3444
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1012
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
695
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.