How do I open remote files in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vivsriaus
Forum Newbie
Posts: 7
Joined: Tue Jan 10, 2006 11:03 am

How do I open remote files in php

Post 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!
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

file_get_contents

Also check your PHP configuration has allow_url_fopen set.
vivsriaus
Forum Newbie
Posts: 7
Joined: Tue Jan 10, 2006 11:03 am

Post 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");
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post 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.
vivsriaus
Forum Newbie
Posts: 7
Joined: Tue Jan 10, 2006 11:03 am

Post 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!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
vivsriaus
Forum Newbie
Posts: 7
Joined: Tue Jan 10, 2006 11:03 am

Post by vivsriaus »

yup!
my file is not http-accessible!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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?
vivsriaus
Forum Newbie
Posts: 7
Joined: Tue Jan 10, 2006 11:03 am

Post by vivsriaus »

Yup! the code is being run on windows! and the good news is that it is running! :o
I made it http readable..that is it! :)
thnx a lot for your suggestions!
Post Reply