Buffering file

Is there a way to buffer a file data into a variable to echo variable later? Other than file_get_contents and require_once is there any other way?

Why?

There is also [fphp]fopen[/fphp] and [fphp]fread[/fphp].

Also please not that require_once does not read the file into a buffer, but executes the php in that file*, so in that way it completely different from file_get_contents (which does buffer the file and returns it so you can store in a variable).

  • You could use require_once in combination with [fphp]ob_start()[/fphp] and [fphp]ob_end_flush()[/fphp], but there aren’t many use cases for this (only templating comes to mind).

Among these 3 functions which one uses stream and which one not? I want to read paypal form file into a variable then pass this variable to the template. How is the best way to do it?

I would use file_get_contents. Short and sweet. No need to use anything complicated.

Why do you want to use streams if you’re only interested in the whole file? Generally you only use streams if you want to process a file bit by bit (i.e. line by line), but that’s not what you’re doing here.

I don’t want to use stream. I asked to make sure which one i should avoid!
Anyway, how do you pass paypal form to template? Do you store it in db? Or in a file then send it as variable to template with file get contents? Or how?

You can do both but I would use a file because it’s easier to maintain.

Then how will you pass the file to template? With gile get content? Or do you use another trick?

$form = file_get_contents(‘/path/to/paypal/form’);

And then send $form to your template.

Is there a anyway to disable in php.ini? I want to make sure if all of my users can use it regardless their php.ini?

No as far as I know it can’t be disabled.

Then how would you prepare the form template with paypal email, amount, currency etc? Do you use tags with str_replace the pass the ready form to template? Or you use php variables in form and pass the vsrisbles to template too?

What kind of templating system are you using? Can’t you just include the PayPal template in your main template?

This is not necessarily paypal. Depends on buyer choice. I use factory class to call related class chosen by buyer and that class call the form file. Now plz answer my question in previous post.

Easiest is a file with PHP, and then do an ob_start, include the file, and get the result with ob_get_cleab. (look then up in the manual)