Andre, here's the function that worked for me...
function file_get_contents($filename) {
$fd = fopen($filename, "r", 1);
$contents = fread($fd, 12000);
fclose($fd);
return $contents;
}
$page_string = file_get_contents("my_file.php");
The third parameter in fopen() [1] can be removed if you don't want to look
for files in your include_path. The second parameter in fread() [12000] is
where I hardcoded the filesize. Increase that number if you'll be opening
larger files.
Originally I had "12000" replaced with "filesize($filename)" but if the
$filename was opened from the include_path, this seems to always return
zero, which is why I hardcoded the byte size into fread().
Monty
> From: [EMAIL PROTECTED] (Andre Dubuc)
> Reply-To: [EMAIL PROTECTED]
> Newsgroups: php.general
> Date: Thu, 18 Jul 2002 17:45:14 -0400
> To: Monty <[EMAIL PROTECTED]>
> Cc: [EMAIL PROTECTED]
> Subject: Re: [PHP] Loading a File into Variable - How??
>
> Hi Monty,
>
> I've been trying to do the same thing with no success. Would you be so kind
> as to show me how you finally did it? I'm not too clear what you meant by:
>
> "So, if I replace the filesize($filename) command with a hard-coded number,
> it works."
>
> Tia,
> Andre
>
> On Thursday 18 July 2002 04:28 pm, you wrote:
>> I just want to load an entire file into a
>> single string variable.
>>
>> However, I figured out the problem shortly after posting that first message
>> (of course). Because the file being opened is in the include_path, it seems
>> filesize() doesn't see those files. So, if I replace the
>> filesize($filename) command with a hard-coded number, it works.
>>
>> Monty
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php