how to open a local file

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
swetha
Forum Commoner
Posts: 88
Joined: Wed Sep 10, 2008 11:00 pm

how to open a local file

Post by swetha »

Code: Select all

 
$fp = fopen("E:Work/Tools/copypaste.php", 'r');
 
i need to open a file in the location which is in the location
"E:Work/Tools/copypaste.php".what is the correct syntax to be given for it in fopen? .when i gave the above syntax,i got the following error:"PHP Warning: fopen(E:Work/Tools/copypaste.php) [function.fopen]: failed to open stream: No such file or directory in E:\Work\Tools for download\filetest1.php on line 10"
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: how to open a local file

Post by papa »

e:/

or relative: ./ depending on where that folder is located.
swetha
Forum Commoner
Posts: 88
Joined: Wed Sep 10, 2008 11:00 pm

Re: how to open a local file

Post by swetha »

i still get the same error after giving this:
fopen("e:/Work/Tools/copypaste.php", 'r')
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: how to open a local file

Post by papa »

Copy the filepath from your explorer and we'll take a look.
swetha
Forum Commoner
Posts: 88
Joined: Wed Sep 10, 2008 11:00 pm

Re: how to open a local file

Post by swetha »

it is actually
E:\Work\Tools for download\text-line.php

the web share name which i have given is Tools
E:\Work\Tools\text-line.php
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: how to open a local file

Post by requinix »

If E:\Work\Tools\text-line.php doesn't exist then it doesn't matter what you think you did.

If you say it's "actually" one path then you should "actually" use that path.
swetha
Forum Commoner
Posts: 88
Joined: Wed Sep 10, 2008 11:00 pm

Re: how to open a local file

Post by swetha »

Please clarify what you are trying to convey.

This is the path "E:\Work\Tools\text-line.php" and this is what i gave in fopen,but it still
gives the error.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: how to open a local file

Post by requinix »

So you tried

Code: Select all

$fp = fopen("E:\Work\Tools\text-line.php", "r");
Right?

See those blue \W \T \ts in there? They're called "metacharacters".
\W and \T don't mean anything so nothing happens to them, but \t means tab.

Code: Select all

$fp = fopen("E:\Work\Tools\    ext-line.php", "r");
Oops.

Use forward slashes, not backslashes.
swetha
Forum Commoner
Posts: 88
Joined: Wed Sep 10, 2008 11:00 pm

Re: how to open a local file

Post by swetha »

with forward slashes,it worked.thanks
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: how to open a local file

Post by s.dot »

Use DIRECTORY_SEPARATOR instead of \ or /.
Usually it does not matter, but it is more elegant and portable and you won't run into any weird problems like that. :)
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
swetha
Forum Commoner
Posts: 88
Joined: Wed Sep 10, 2008 11:00 pm

Re: how to open a local file

Post by swetha »

how do i use DIRECTORY_SEPARATOR ?
Post Reply