Jump to content

working with .php files.


Ninjakreborn

Recommended Posts

does this help?

$infile = fopen("myfile.txt", "r") // as readonly
while (!feof($infile))
{
$buffer = fgets($infile, 2048); // or $buffer = fread($infile.....
}
fclose($infile);

// do whatever you want

$outfile = fopen("mynewfile.txt", "w") // open writeable
fwrite($outfile, $buffer)
fclose ($outfile);

cheers,
tdw
Link to comment
Share on other sites

[code]$infile = fopen("myfile.txt", "r") // as readonly
while (!feof($infile))
{
$buffer = fgets($infile, 2048); // or $buffer = fread($infile.....
}
fclose($infile);

// do whatever you want

$outfile = fopen("mynewfile.txt", "w") // open writeable
fwrite($outfile, $buffer)
fclose ($outfile);[/code]
Now to break this down.
So the open, that is opening the file as read only.  I got that part.
Then
[code]while (!feof($infile))
{
$buffer = fgets($infile, 2048); // or $buffer = fread($infile.....
}[/code]
I can look up end of file function on php.net, but what would the difference be in fgets and file_get_contents
Which would be better Also what is the 2048,
I appreciate the help so far, thanks.
It looks like the top part opens the file, saves the info in a variable.
then closes the file
then it attempts to oepn another file, if one doesn't exist then obviously it creates it, then it writes that information to it, and that's it right.
Link to comment
Share on other sites

hi

well [color=blue]fread[/color] reads a total amount up to length, and [color=blue]fgets[/color] reads it line by line

so if you want to read it all in one go you can use
[code]$buffer = fread($infile, filesize("myfile.txt")); // or use a variable for the filename[/code]

or to only read a portion of it you can specify the number of bytes to read: (2kbs in this example)
[code]$buffer = fread($infile, 2048); // or use a variable for the filename[/code]

or to read the file line by line so you can deal with each line while reading it, you use fgets and specify the number of bytes to read (in that line): (2kbs in this example)
[code]$buffer = fgets($infile, 2048); // or use a variable for the filename[/code]

i dont know about [color=blue]get_file_contents[/color]

and then yes, the "w" in fopen means will attempt to create it, so check your permissions in the folder

[code]$outfile = fopen("mynewfile.txt", "w")[/code]

cheers,
tdw
Link to comment
Share on other sites

Well I did some modifications, I am going to have to instead carry all of this information over into paypal's IPN, and then do all this stuff there I think.  I will have to store the text, and template they choose into a session, and let the stuff that comes back from paypal deal with it.  I can only hope that when paypal sends the ipn back to the script that I can have the sessions available to do what I need.  If not, I can pass it all through paypal, I think that would be the best time to do all of this, so I can have a full system built.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.