Page 1 of 1

how to open a local file

Posted: Thu Oct 23, 2008 5:50 am
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"

Re: how to open a local file

Posted: Thu Oct 23, 2008 6:08 am
by papa
e:/

or relative: ./ depending on where that folder is located.

Re: how to open a local file

Posted: Thu Oct 23, 2008 11:48 pm
by swetha
i still get the same error after giving this:
fopen("e:/Work/Tools/copypaste.php", 'r')

Re: how to open a local file

Posted: Fri Oct 24, 2008 12:46 am
by papa
Copy the filepath from your explorer and we'll take a look.

Re: how to open a local file

Posted: Fri Oct 24, 2008 2:44 am
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

Re: how to open a local file

Posted: Fri Oct 24, 2008 3:03 am
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.

Re: how to open a local file

Posted: Tue Oct 28, 2008 10:01 pm
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.

Re: how to open a local file

Posted: Tue Oct 28, 2008 10:16 pm
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.

Re: how to open a local file

Posted: Thu Oct 30, 2008 1:04 am
by swetha
with forward slashes,it worked.thanks

Re: how to open a local file

Posted: Thu Oct 30, 2008 1:36 am
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. :)

Re: how to open a local file

Posted: Thu Oct 30, 2008 7:56 am
by swetha
how do i use DIRECTORY_SEPARATOR ?