tags:

views:

169

answers:

2

HI. i am trying to open a local file from xml created by xlink i have parsed the file path in $resourceRef variable and it looks like that file:/./birds/birds.txt without the quotes. Please someone tell me why i cant open it. here is my code

$fh = fopen($resourceRef, 'r');
$theData = fread($fh, filesize($resourceRef));
fclose($fh);
echo $theData;

i get this error

Warning: fopen(file:/./birds/feathers.txt) [function.fopen]: failed to open stream: Invalid argument in C:\xampp\htdocs\test.php on line 31

Please someone guide me.

A: 

Argument should be suitable path for a given platform (For widows "C:\\dir(...)" ), or correct URI ( file:// (...) )

canni
file:/./birds/birds.txt is in the xml file and its done by using xlink. how can i change it..there are or will be a lot
Zero Cool
use string replace function to replace "file:/./" to "file://./" this will correct string to valid URI, but still You have to deal with relative paths, (that dot in path) for this to work, php script should be in same directory as xlink generated file
canni
what about if i take away file:/./ from file:/./birds/birds.txt so it will be birds/birds.txt and it works . i think this should be better. all the links and pictures, txt files are in a seperate folder.do u think i can do it by using string replace or some other function.
Zero Cool
You have to convert string, to a valid path or a valid URI, in any other case, fopen will fail to open file, You can use regular expressions, string replace function and any other bunch of available stuff to make this a valid information, about where file lays :)
canni
and PHP gives You functions such as file_exists($file) to test/help if You have changed file path/URI correctly.For example: remove (replace file:/./ to empty string), and perpend a valid path for directory where You have that files, to file name, if done right, should work
canni
+1  A: 

Your URI doesn't look correct, it should be either file://birds/birds.txt or just birds/birds.txt.

DASPRiD
file:/./birds/birds.txt is in the xml file and its done by using xlink. how can i change it..there are or will be a lot...please advise me is there a way i can do it.
Zero Cool
How about a simple str_replace('file:/', 'file://'); ?
DASPRiD
i think i am gonna try that it sounds better thanks DSAPRiD
Zero Cool