Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I am trying to read a JavaScript file.
Permissions have been set to 755.

Do I have to open the file first?
fopen($filename, "rb");

Then read it?

My script:

$filename = " ";
echo "File name = ".$filename;  This echoes the correct name and path.

$fileopen = fopen($filename, "rb");
echo "File open = ".$fileopen;  This echoes Resource id #4
     What is resource id #4?
     Where do I find a definition of resource id #4?

$contents = fread($fileopen, filesize($fileopen));
echo "File size = ".filesize($filename);  This echo is empty.
echo "Contents = ".$contents;  This echo is empty.



Re: fread()

AFAIK you can't request the filesize of a remote file (perhaps in PHP

Try something like this:

$strURL = ' ';
$strText = '';
$fh = fopen( $strURL, 'r') or die( $php_errormsg );
while( !feof( $fh ) )
$strText .= fread( $fh, 1024 );
fclose( $fh );
header( 'Content-type: text/plain' );
print $strText;


Re: fread()


Quoted text here. Click to load it


fopen() returns an ID that denotes the currently opened file. It's a
handle for all further actions performed on that file.

Quoted text here. Click to load it

Resource-IDs are a special type in PHP.

Quoted text here. Click to load it

You can't use filesize() on remote files in PHP4.

Quoted text here. Click to load it

This should be


You could also try this simple code instead:

$filename = 'http://...';
$content = file_get_contents($filename);


Site Timeline