writing a file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
visonardo
Forum Contributor
Posts: 136
Joined: Mon Oct 02, 2006 7:49 pm
Location: Argentina, South America´s Sun.

writing a file

Post by visonardo »

Hi, i want know how can i know how many lines has a txt files that im reading. I need know that before work over it.
My problem is that my server doesnt allow me to enable a determinate ip mine to conect from my pc (using mysql administrator) to the server to do the backup here in my pc. I know how to write a txt file, but the bd is like 230mb. I was thinking in a system that write up to (for example) make a file of 1mb and then it done continue the backup in other file. Do im clear? that i need is how to control rigurously how many data i wroted and i would write in the next line and thus each time.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

I'm having difficulty understanding your english ;) but if I've understood you correctly you simply need to open the file in "append" mode:

Code: Select all

$handle = fopen($file, "a+");
This way you can write a line, then discard that line and each time you write to the file it just adds to the end of it. You'll save memory compared with writing in "write" mode (the w flag).

I hope that's what you were asking? :)
Post Reply