473,224 Members | 1,477 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

problem with file()

vKp
I'm having a problem with file(). If I try to open a url of the form
"http://example.com/find?one,two", I get an error of the following form:

....failed to create stream: Bad file descriptor...

What's going wrong? How can I make this work? (Note that I have no
control over the form of the remote urls).

Jul 17 '05 #1
9 4316
vKp wrote:
I'm having a problem with file(). If I try to open a url of the form
"http://example.com/find?one,two", I get an error of the following form:

...failed to create stream: Bad file descriptor...

What's going wrong? How can I make this work? (Note that I have no
control over the form of the remote urls).


Use error suppressing and error checking :-)

<?php
$url = 'http://www.example.com/find?one,two';
$x = @file($url); // @ for error suppressing
if ($x === false) {
// error checking, maybe
die('Invalid URL');
} // else continue
?>
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #2
vKp
Pedro Graca wrote:
vKp wrote:
I'm having a problem with file(). If I try to open a url of the form
"http://example.com/find?one,two", I get an error of the following form:

...failed to create stream: Bad file descriptor...

What's going wrong? How can I make this work? (Note that I have no
control over the form of the remote urls).

Use error suppressing and error checking :-)

<?php
$url = 'http://www.example.com/find?one,two';
$x = @file($url); // @ for error suppressing
if ($x === false) {
// error checking, maybe
die('Invalid URL');
} // else continue
?>

I think that I wasn't very clear. Surpressing the error won't help,
because I need it to open the url. It IS a valid url. I've accessed it
via IE and gecko based browsers. What I really need to know is why PHP
won't open it.

Thanks for your reply though :)

Jul 17 '05 #3
On Wed, 21 Jan 2004 21:37:19 +0000, vKp <as*****@hotmail.com> wrote:
I'm having a problem with file(). If I try to open a url of the form
"http://example.com/find?one,two", I get an error of the following form:

...failed to create stream: Bad file descriptor...

What's going wrong? How can I make this work? (Note that I have no
control over the form of the remote urls).


PHP version? allow_url_fopen enabled? http listed in the Registered PHP
Streams section of phpinfo()? Minimal example code demonstrating problem?

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
<http://www.andyh.co.uk> / <http://www.andyhsoftware.co.uk/space>
Jul 17 '05 #4
vKp wrote:

Pedro Graca wrote:
vKp wrote:
I'm having a problem with file(). If I try to open a url of the form
"http://example.com/find?one,two", I get an error of the following form:

...failed to create stream: Bad file descriptor...

What's going wrong? How can I make this work? (Note that I have no
control over the form of the remote urls).

Use error suppressing and error checking :-)

<?php
$url = 'http://www.example.com/find?one,two';
$x = @file($url); // @ for error suppressing
if ($x === false) {
// error checking, maybe
die('Invalid URL');
} // else continue
?>

I think that I wasn't very clear. Surpressing the error won't help,
because I need it to open the url. It IS a valid url. I've accessed it
via IE and gecko based browsers. What I really need to know is why PHP
won't open it.


Without the real url, it's hard to say, but you might try url_encode()ing it.
IE will take and convert some invalid URL characters (ie. spaces). So opening a
link in IE is not a good test of a URL's validity.

If that's not your problem, I'd try all of Andy's suggestions, then
fsockopen(). I had some trouble at one point trying to open a webpage. It
turned out that you had to set a USER_AGENT to view the webpage (it was an
anti-spambot feature of fark.com). I never would have figured that out because
the link always came up fine in IE and NS.

Regards,
Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com

I have a spam filter. Please include "PHP" in the
subject line to ensure I'll get your message.
Jul 17 '05 #5
vKp
Andy Hassall wrote:

PHP version? allow_url_fopen enabled? http listed in the Registered PHP
Streams section of phpinfo()? Minimal example code demonstrating problem?


4.3.1 (Can't upgrade), allow_url_fopen is on, and http is listed.
The exact code that causes the problem is:

$Name = "Buscemi,Steve";
$Name = urlencode($Name); //fails with or without urlencoding
$BaseURL = "http://us.imdb.com/Name?" . $Name;

$URL = join ("", file($BaseURL));
echo $URL;

This results in:
Warning: file(http://us.imdb.com/Name?Buscemi%2CSteve) [function.file]:
failed to create stream: Bad file descriptor in [... file name at the
join line...]

I really can't understand what's going on.

Jul 17 '05 #6
On Wed, 21 Jan 2004 23:33:39 +0000, vKp wrote:

I think that I wasn't very clear. Surpressing the error won't help,
because I need it to open the url. It IS a valid url. I've accessed it
via IE and gecko based browsers. What I really need to know is why PHP
won't open it.

Could it be that your host has blocked outbound port 80 from the server?
Or perhaps the remote site has blocked your server's IP address?

Try telnetting to the remote server (port 80) and doing something like

GET /file?value=x&variable=y HTTP/1.0

(that's two carriage returns, btw)

And see what comes back, in case it isn't quite so valid a URL as you
thought.
One thing that people sometimes miss is that you need to put a / at the
end of directories -

For example:

http://something.org/hello

points to a file called hello

and

http://something.org/hello/

points to a directory called hello, and will probably return a file called
something along the lines of index.php or default.asp (depending on the
server and configuration), or a directory listing, or a directory listing
denied message.

HTH,

AdamT
Jul 17 '05 #7
vKp <as*****@hotmail.com> wrote:
This results in:
Warning: file(http://us.imdb.com/Name?Buscemi%2CSteve) [function.file]:
failed to create stream: Bad file descriptor in [... file name at the
join line...]

I really can't understand what's going on.


The url above will result in a redirect:

GET /Name?Buscemi%2CSteve HTTP/1.1
Host: us.imdb.com
[snip]

HTTP/1.1 302 Found
Date: Thu, 22 Jan 2004 17:44:14 GMT
Server: Apache
Location: /find?q=Buscemi,Steve;nm=1
[snip]

maybe you are experiencing a bug? But it works for me on 4.1.2....

--

Daniel Tryba

Jul 17 '05 #8
On Thu, 22 Jan 2004 16:24:10 +0000, vKp <as*****@hotmail.com> wrote:
Andy Hassall wrote:

PHP version? allow_url_fopen enabled? http listed in the Registered PHP
Streams section of phpinfo()? Minimal example code demonstrating problem?


4.3.1 (Can't upgrade), allow_url_fopen is on, and http is listed.
The exact code that causes the problem is:

$Name = "Buscemi,Steve";
$Name = urlencode($Name); //fails with or without urlencoding
$BaseURL = "http://us.imdb.com/Name?" . $Name;

$URL = join ("", file($BaseURL));
echo $URL;

This results in:
Warning: file(http://us.imdb.com/Name?Buscemi%2CSteve) [function.file]:
failed to create stream: Bad file descriptor in [... file name at the
join line...]

I really can't understand what's going on.


Works for me, PHP 4.3.4. Search on bugs.php.net, there seem to be a few
reports of similar things, fixed in various versions and re-emerging again in
others.

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
<http://www.andyh.co.uk> / <http://www.andyhsoftware.co.uk/space>
Jul 17 '05 #9
vKp
Andy Hassall wrote:


Works for me, PHP 4.3.4. Search on bugs.php.net, there seem to be a few
reports of similar things, fixed in various versions and re-emerging again in
others.


Thanks for the help. It appears to be a bug. I tried the same code on
servers running 4.1.1 and 4.3.4, and it worked fine. So just need to
upgrade my local server (hopefully).

Thanks.

Jul 17 '05 #10

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

Similar topics

7
by: Keith Dewell | last post by:
Greetings! My current job has brought me back to working in C++ which I haven't used since school days. The solution to my problem may be trivial but I have struggled with it for the last two...
12
by: SJD | last post by:
I've just read Christoph Schittko's article on XmlSerializer: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnxmlnet/html/trblshtxsd.asp . . . and very informative it is too....
15
by: Ken Allen | last post by:
I have been developing a suite of assemblies over the past couple of weeks, and this afternoon somethign started misbehaving. If I do not run the IDE and compiler the code from the command line,...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
5
by: IkBenHet | last post by:
Hello, I use this script to upload image files to a folder on a IIS6 server: ******************* START UPLOAD.ASPX FILE ********************** <%@ Page Language="VB" Debug="true" %>
8
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...
13
by: Lee Newson | last post by:
Hi, I have just written my first application using VB.NET. The app works fine when i am running it within .NET for debugging purposes, however when i try to run the app from the .exe file that...
2
by: key9 | last post by:
Hi all on last post I confused on how to organize file of class, ok ,the problem solved : should include class define head on cpp file. but this time ,still link error: strange is I put the...
0
by: anide | last post by:
Hi all Iíve some problem, Iím trying to converting a sorting algorithm from C++ to C#. In C++ Iíve compiled it using MSVC and its working properly, and in C# Iím using .NET Framework 2.0 (Visual...
4
by: Salad | last post by:
I have a situation where some, not all, users get the message "Couldn't find file "F:\AccessApps\AppName.mdw". This file is required for startup". My app the users are attempting to access is...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.