|
|
 |
file_get_contents (PHP 4 CVS only) file_get_contents -- Reads entire file into a string Descriptionstring file_get_contents ( string filename [, int use_include_path])
Identical to readfile(), except that
file_get_contents() returns the file in a string.
Note: This function is
binary-safe.
Tip: You can use a URL as a
filename with this function if the fopen wrappers have been enabled.
See fopen() for more details on how to specify
the filename and Appendix I for a list of supported
URL protocols.
See also: fgets(), file(),
fread(), include(),
and readfile().
User Contributed Notes file_get_contents |
 |
ericston_ at _home_ dot _nl
11-Apr-2002 12:24 |
|
If you use PHP < 4.3.0, you could try: $string =
implode("", file($filename));
Not talking about
efficiency here, though.
|
|
nospam at g4s dot dk
05-May-2002 10:46 |
|
If you are not using the CVS version of PHP you can use this
functon:
function file_get_contents($filename, $use_include_path =
0) { $fd = fopen ($filename, "rb", $use_include_path);
$contents = fread($fd, filesize($filename)); fclose($fd); return
$contents; }
If you have access to the php.ini file you can also
create a PHP script which will automatically be included in each page
using the auto_prepend_file directive.
|
|
zzzhong at remove_this_nospam dot yahoo dot com
11-Sep-2002 10:36 |
|
some problems of previous code 1. file function is not binary save 2.
filesize does not support url filename i've tried this code to be
work
function file_get_contents($filename) { $fp =
@fopen($filename, "r"); if (!($fp)) { return
0; } while (!feof($fp)) { $temp .= fread($fp,
4096); } return $temp; }
|
|
ger dot Shaker at gmx dot net
09-Oct-2002 06:25 |
|
Here is my Code how to Copy a file from a website to local harddisk
without the file_get_contents function. it is binary-safe, but its not
the fastest way:
function filecopy($urlsrc,$localdst)
{ $fp_urlsrc = /old?u=http%3A%2F%2Ffr.php.net%2Fmanual%2Fen%2Ffopen%28%24urlsrc%2C%26quot%3Br%26quot%3B%29%3B%3Cbr&y=1999>$del_File =
fopen($localdst,"w"); fwrite($del_File,""); fclose
($del_File); while (!feof($fp_urlsrc)) { $fp_localdst =
fopen($localdst,"a"); fwrite ($fp_localdst,
fread($fp_urlsrc, 1)); fclose
($fp_localdst); } fclose($fp_urlsrc); }
|
|
adam at tylmad dot com
14-Oct-2002 12:02 |
|
My php-installation didn't have file_get_contents so I implemented my own
version. It takes to args, source URL to download from and target local
path to save to... enjoy
function download($url,
$local) { $readfile = @fopen($url, "rb"); $writefile
= @fopen($local, "wb"); while
(!feof($readfile)) fwrite($writefile, fread($readfile,
65535)); fclose($readfile); fclose($writefile); }
|
|
alfred at oddbooks dot com
14-Nov-2002 04:30 |
|
Another thing to note if you use the first roll-your-own version of
file_get_contents() above is that filesize() is cached. If you rewrite a
file that may later be read using this function you should then call
clearstatcache() to ensure the right value is returned by filesize().
|
|
 |
| |