I apologize if this is a pretty novice question but I'm learning PHP and have been having trouble writing a web service.
When I use fopen($fullfilename, 'r')
it returns two errors:
Warning: fopen() [function.fopen]: remote host file access not supported
Warning: fopen(file://filepath) [function.fopen]: failed to open stream: no suitable wrapper could be found
The filepath I'm using is the absolute path to the file on my local computer. I'm using a Mac if that makes any difference. Any help would be greatly appreciated!
You could try the relative path from the php file where the
fopen($fullfilename, 'r')
line can be found
For example:
/*
/usr/You/Documents/project/myproject/myfolder/myscript.php
/usr/You/Documents/project/myproject/mydata/datafile.txt
*/
$fullfilename = "../mydata/datafile.txt";
$contents = fopen($fullfilename, 'r');
Should work ok.
When accessing files on the local system, you don't need the http://
or file:///
. You just need the path to the file, like if you were accessing from the machine itself.
You just need to do:
fopen('/path/to/file', 'r')
echo( "<pre>");
$fullfilename = "C:\Users\Documents\hey.txt";
$gg = fopen($fullfilename, 'r') or die("file doesnt exist");
// for entire read of doc use file_get_contents($fullfilename)
$readtext = fread($gg, 3000); //read 3000 chars of doc
fclose($gg);
echo $readtext;
echo "</pre >";
hope it helps, thanks
Try:
$filename = realpath($fullfilename);
var_dump($filename);
What does it return? If it returns bool(false), the path/file doesn't exist here.