Page 1 of 1
How do I open remote files in php
Posted: Tue Jan 10, 2006 11:09 am
by vivsriaus
Hey all,
I'm in a fix and am not able to solve this problem!
I have a file located on a server machine and I wanna read that file!
the server name is server.safl.umn.edu
and, if I specify this $file = '\\server.safl.umn.edu\common\cellis\safl weather\saf_wthr.dat'; $fp = fopen($file,"r")
it gives me the following error
Warning: fopen(\server.safl.umn.edu\common\cellis\safl weather\saf_wthr.dat) [function.fopen]: failed to open stream: No such file or directory in C:\websites\techtest.safl.umn.edu\Vivek\demo3.php on line 54
All the access permissions are there, but it just doesnt work!
Posted: Tue Jan 10, 2006 11:39 am
by Maugrim_The_Reaper
file_get_contents
Also check your PHP configuration has allow_url_fopen set.
Posted: Tue Jan 10, 2006 12:04 pm
by vivsriaus
Hey, thanks for the reply
But it still doesnt work!
string file_get_contents ( string filename [, bool use_include_path [, resource context [, int offset [, int maxlen]]]] )
I dont think, apart from the filename, the other parameters r compulsory!
Btw, i'm not sure what resource context means!
Please tell me if this syntax is correct!
$file = file_get_contents("\\server.safl.umn.edu\common\cellis\safl weather\saf_wthr.dat");
Posted: Tue Jan 10, 2006 12:32 pm
by patrikG
vivsriaus wrote:Hey, thanks for the reply
But it still doesnt work!
string file_get_contents ( string filename [, bool use_include_path [, resource context [, int offset [, int maxlen]]]] )
I dont think, apart from the filename, the other parameters r compulsory!
Btw, i'm not sure what resource context means!
Please tell me if this syntax is correct!
$file = file_get_contents("\\server.safl.umn.edu\common\cellis\safl weather\saf_wthr.dat");
Try it out, see what happens. Best way to learn.
Posted: Tue Jan 10, 2006 12:45 pm
by vivsriaus
its not that I didnt try it!
it gives me the same error!
I used file_exists as well to chk if there is a file pointer to it!
and it doesnt exist!!
I dont know how to open a remote file, as simple as that!
any help will b much appreciated!
Posted: Tue Jan 10, 2006 2:11 pm
by feyd
You want to read the file through Windows UNC? that's a bit more complicated last I saw. It would be easier to access a remote HTTP-accessible file.
Posted: Tue Jan 10, 2006 2:27 pm
by vivsriaus
yup!
my file is not http-accessible!
Posted: Tue Jan 10, 2006 3:06 pm
by feyd
try this first
Code: Select all
$file = '\\\\server.safl.umn.edu\\common\\cellis\\safl weather\\saf_wthr.dat';
Although I don't remember if php understands Windows UNC coding, natively.. I'd seem to remember it doesn't. Is the code being run on a Windows machine?
Posted: Tue Jan 10, 2006 4:32 pm
by vivsriaus
Yup! the code is being run on windows! and the good news is that it is running!
I made it http readable..that is it!
thnx a lot for your suggestions!