How to get contents of a file with querystring ?
How to get contents of a file with querystring ?
am 27.08.2007 12:13:12 von puginews
For obtaining the contents of a file one can use the file_get_contents
function.
But when I try to use this function to get the contents of file
including a querystring I always get a failed to open stream, no such
file or directory.
$str = file_get_contents('/dir1/dir2/dir3/file.php?
param1=12¶m2=log¶m3=5');
The contents of the file can either be text or json encoded.
For an xml response it works $xml->load('/dir1/dir2/dir3/file.php?
param1=12¶m2=log¶m3=5').
But it should be possible for txt or json too .. I guess ?
What other functions are there to get the contents of a file with
querystring ?
thanx,
Pugi!
Re: How to get contents of a file with querystring ?
am 27.08.2007 12:19:29 von puginews
On 27 aug, 12:13, Pugi! wrote:
> For obtaining the contents of a file one can use the file_get_contents
> function.
> But when I try to use this function to get the contents of file
> including a querystring I always get a failed to open stream, no such
> file or directory.
> $str = file_get_contents('/dir1/dir2/dir3/file.php?
> param1=12¶m2=log¶m3=5');
> The contents of the file can either be text or json encoded.
> For an xml response it works $xml->load('/dir1/dir2/dir3/file.php?
> param1=12¶m2=log¶m3=5').
> But it should be possible for txt or json too .. I guess ?
> What other functions are there to get the contents of a file with
> querystring ?
>
> thanx,
>
> Pugi!
It is information I want to send from one php file to another.
Should I use a specific header when sending json encoded information
like one has to in the case of xml ?
Pugi!
Re: How to get contents of a file with querystring ?
am 27.08.2007 12:40:15 von Jerry Stuckle
Pugi! wrote:
> On 27 aug, 12:13, Pugi! wrote:
>> For obtaining the contents of a file one can use the file_get_contents
>> function.
>> But when I try to use this function to get the contents of file
>> including a querystring I always get a failed to open stream, no such
>> file or directory.
>> $str = file_get_contents('/dir1/dir2/dir3/file.php?
>> param1=12¶m2=log¶m3=5');
>> The contents of the file can either be text or json encoded.
>> For an xml response it works $xml->load('/dir1/dir2/dir3/file.php?
>> param1=12¶m2=log¶m3=5').
>> But it should be possible for txt or json too .. I guess ?
>> What other functions are there to get the contents of a file with
>> querystring ?
>>
>> thanx,
>>
>> Pugi!
>
> It is information I want to send from one php file to another.
> Should I use a specific header when sending json encoded information
> like one has to in the case of xml ?
>
> Pugi!
>
file_get_contents() does just that - it fetches the contents of the
file. Nothing more, nothing less.
The only way you can pass a query string to a file is to get it through
the web server - that is, load it as a URL. But that requires an
additional round trip to the server and added overhead.
Maybe you should rethink your design.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: How to get contents of a file with querystring ?
am 27.08.2007 14:01:59 von puginews
On 27 aug, 12:40, Jerry Stuckle wrote:
> Pugi! wrote:
> > On 27 aug, 12:13, Pugi! wrote:
> >> For obtaining the contents of a file one can use the file_get_contents
> >> function.
> >> But when I try to use this function to get the contents of file
> >> including a querystring I always get a failed to open stream, no such
> >> file or directory.
> >> $str = file_get_contents('/dir1/dir2/dir3/file.php?
> >> param1=12¶m2=log¶m3=5');
> >> The contents of the file can either be text or json encoded.
> >> For an xml response it works $xml->load('/dir1/dir2/dir3/file.php?
> >> param1=12¶m2=log¶m3=5').
> >> But it should be possible for txt or json too .. I guess ?
> >> What other functions are there to get the contents of a file with
> >> querystring ?
>
> >> thanx,
>
> >> Pugi!
>
> > It is information I want to send from one php file to another.
> > Should I use a specific header when sending json encoded information
> > like one has to in the case of xml ?
>
> > Pugi!
>
> file_get_contents() does just that - it fetches the contents of the
> file. Nothing more, nothing less.
>
> The only way you can pass a query string to a file is to get it through
> the web server - that is, load it as a URL. But that requires an
> additional round trip to the server and added overhead.
>
> Maybe you should rethink your design.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================
Hmm, but it works for xml; you can the pass the DOMDocument->load a
path-file-querystring without round trip to the server.
In order to get a response from a file + querystring (for json, text,
html) one always need a round trip to server, except for xml ?
Pugi!
Re: How to get contents of a file with querystring ?
am 27.08.2007 14:20:19 von Jerry Stuckle
Pugi! wrote:
> On 27 aug, 12:40, Jerry Stuckle wrote:
>> Pugi! wrote:
>>> On 27 aug, 12:13, Pugi! wrote:
>>>> For obtaining the contents of a file one can use the file_get_contents
>>>> function.
>>>> But when I try to use this function to get the contents of file
>>>> including a querystring I always get a failed to open stream, no such
>>>> file or directory.
>>>> $str = file_get_contents('/dir1/dir2/dir3/file.php?
>>>> param1=12¶m2=log¶m3=5');
>>>> The contents of the file can either be text or json encoded.
>>>> For an xml response it works $xml->load('/dir1/dir2/dir3/file.php?
>>>> param1=12¶m2=log¶m3=5').
>>>> But it should be possible for txt or json too .. I guess ?
>>>> What other functions are there to get the contents of a file with
>>>> querystring ?
>>>> thanx,
>>>> Pugi!
>>> It is information I want to send from one php file to another.
>>> Should I use a specific header when sending json encoded information
>>> like one has to in the case of xml ?
>>> Pugi!
>> file_get_contents() does just that - it fetches the contents of the
>> file. Nothing more, nothing less.
>>
>> The only way you can pass a query string to a file is to get it through
>> the web server - that is, load it as a URL. But that requires an
>> additional round trip to the server and added overhead.
>>
>> Maybe you should rethink your design.
>>
>
> Hmm, but it works for xml; you can the pass the DOMDocument->load a
> path-file-querystring without round trip to the server.
> In order to get a response from a file + querystring (for json, text,
> html) one always need a round trip to server, except for xml ?
>
> Pugi!
>
And are you sure the querystring is being parsed? Or is it just being
stripped by the load() function? I admit I've never tried a query
string with DOMDOcument->load.
But I do know file_get_contents() and the other file calls (i.e. fopen,
etc), when applied to the file system, just retrieve the file. Period.
If the file has executable code, the code is NOT executed - rather it is
returned to the program in a string. And if you echo it, you echo the
code itself.
I don't think that's what you want. And I still think your design has
some problems. But not knowing what you're trying to accomplish, I have
no idea what might be lacking.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: How to get contents of a file with querystring ?
am 28.08.2007 05:28:45 von Norman Peelman
Pugi! wrote:
> For obtaining the contents of a file one can use the file_get_contents
> function.
> But when I try to use this function to get the contents of file
> including a querystring I always get a failed to open stream, no such
> file or directory.
> $str = file_get_contents('/dir1/dir2/dir3/file.php?
> param1=12¶m2=log¶m3=5');
> The contents of the file can either be text or json encoded.
> For an xml response it works $xml->load('/dir1/dir2/dir3/file.php?
> param1=12¶m2=log¶m3=5').
> But it should be possible for txt or json too .. I guess ?
> What other functions are there to get the contents of a file with
> querystring ?
>
> thanx,
>
> Pugi!
>
file_get_contents() is expecting to find a file named:
file.php?param1=12¶m2=log¶m3=5
and is not finding it (of course). If you try to open just file.php
you'll see you get a valid resource. You probably want to use fopen()
or another.
Norm
Re: How to get contents of a file with querystring ?
am 28.08.2007 20:01:19 von nc
On Aug 27, 3:13 am, Pugi! wrote:
>
> For obtaining the contents of a file one can use the
> file_get_contents function.
Yes, but one must also remember that in programming, one gets exactly
what one asks for. :)
> But when I try to use this function to get the contents of file
> including a querystring I always get a failed to open stream, no such
> file or directory.
> $str = file_get_contents('/dir1/dir2/dir3/file.php?
> param1=12¶m2=log¶m3=5');
But of course. You are asking for a local file, but append a query
string to the name. If you want to get the output of a local script,
you should ask properly:
$str = file_get_contents('http://localhost/dir1/dir2/dir3/file.php? ' .
. 'param1=12¶m2=log¶m3=5');
> The contents of the file can either be text or json encoded.
> For an xml response it works $xml->load('/dir1/dir2/dir3/file.php?
> param1=12¶m2=log¶m3=5').
Well, which XML parser class are you using? It's possible that the
parser class you are using treats the argument to the load() method as
a URL...
Cheers,
NC