File handling documentation

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
Dilbert137
Forum Commoner
Posts: 57
Joined: Sat Jun 02, 2007 5:02 am
Location: Mauritius

File handling documentation

Post by Dilbert137 »

Dear All,

I need to create a function for updating pricelist on database and need some documentations on file handling on PHP. Could you please refer me a documentation?

Thanks and Best Regards
Dilbert137
Last edited by Dilbert137 on Tue Jul 10, 2007 11:39 am, edited 1 time in total.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

A: What have you tried?
B: php.net
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

fopen, fread, fwrite are the only functions you need to know. :)

You could use my CSV class to simplify matters, located here:

viewtopic.php?t=47855

Whats really weird, is you use the term database and file handling in the same sentance, which is accurate when using DB tin it's most generic sense. However in PHP when you say DB, you typically mean MySQL, SQLite, etc.

So just to clear things up, what exactly are you looking to use? DB or File system?
Dilbert137
Forum Commoner
Posts: 57
Joined: Sat Jun 02, 2007 5:02 am
Location: Mauritius

Post by Dilbert137 »

I will use Mysql as database and a table price in which prices must be updated from a text file. In the text file there will be product id and prices. I will import data from the text file and write it in my mysql table.

Thanks
Dilbert137
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

In that case, make a small script that just takes the data in a textarea and paste it in there. Press submit and have it add each record to the database using the submitted data.
Dilbert137
Forum Commoner
Posts: 57
Joined: Sat Jun 02, 2007 5:02 am
Location: Mauritius

Post by Dilbert137 »

Hi superdezign,

No the solution to take from a textarea is not recommended when you have more than 1000 product items prices to be changed and when you have different price list. Data must be taken from a text file or automatic update. But my solution for the moment is this one.

Regards
Dilbert137
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

When dealing with text files, textareas are actually perfectly fine. You'll be dealing with the exact same amount of data.

If you really don't want to use it, you should have already visited the resources we've given so far and looked into the file handling functions. The processing will be the same.
Dilbert137
Forum Commoner
Posts: 57
Joined: Sat Jun 02, 2007 5:02 am
Location: Mauritius

Post by Dilbert137 »

Sorry I don't really understand you. Maybe your solution is fine. My understanding of textarea is the testarea used in forms. Documentation is needful as it will be confusing. In IT there are so many way that it can be done but with textarea not for so huge data and when specific field have to be extracted.

I use textarea when there is wordings to be inserted in table field but not for specific data to be collect from.

<textarea></textarea>

Regards
Dilbert137
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Well the best way to understand a text area is that it's just text. There's no limit. It would only remove the need to handle the files.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

If you have file that contains somezhing like
productid,price
productid,price
productid,price
you might be interested in http://de2.php.net/fgetcsv

Code: Select all

<?php
$fp = fopen('data.txt', 'rb') or die('cannot open file');
while( !feof($fp) ) {
	$row = fgetcsv($fp);
	print_r($row);
}
Dilbert137
Forum Commoner
Posts: 57
Joined: Sat Jun 02, 2007 5:02 am
Location: Mauritius

Post by Dilbert137 »

Thanks
Dilbert137
Dilbert137
Forum Commoner
Posts: 57
Joined: Sat Jun 02, 2007 5:02 am
Location: Mauritius

Post by Dilbert137 »

I thank you all. I have been able to import data from a file so that to insert it into my table. The help of all those replying to my post was helpful to me.

Thanks a lot
Dilbert137
Post Reply