View Full Version : How do i save db field data to a file on the server?

01-06-2007, 03:58 AM

I have a form full of data that needs to get saved in a db - not a problem.

What i now need to do is find a way where, one of fields in one table points to a file in a folder on the server . Now this file is a doc file - a report that gets updated all the time by different users.

For simplicity, lets say, this form holds address data of 10 persons. Now lets assume they change homes frequently and since each knows the address of the other, the street field in Record A, originally entered by User A, can be modified by User B and then posted back to its place . Similarly, Users C and D can change the street name but Users E-J can only view the addresses but not edit it.

Now all street field data is stored in public/html/domain/Addresses/England folder on the Server and the file they are stored in is Engadd.doc . I need to be able to call Engadd.doc and then have the records added, modified or viewed.

I'm pretty much set for most of this code but I'm not sure what kind of syntax to use to be able to call,edit and then upload both $street and Engadd to its place.

The possibility of doing and INSERT or UPDATE $street = $_POST["street"]; is not on because that only saves $street in the table field but not in the file on the folder.

Would anyone guide me on this please ?

Thanks !

01-06-2007, 05:29 PM
Sooo.... you just need to know how to edit a file? If it is a text file then you should be able to do this. (won't work if it's a Word file.) Open the file using fopen() (http://us2.php.net/manual/en/function.fopen.php) with a mode of "r+" which means you can read and write the file. You'll then have to read through the file sequentially and use fwrite() to change records as you see fit.

I sometimes just read an entire file into an array using file() (http://us2.php.net/manual/en/function.file.php), then re-create the file by using mode "a" with fopen, parsing through the array and fwrite() as I go, changing what I need to change along the way.

01-06-2007, 06:48 PM
i need to edit AND store it on the server in a folder . And it is doc not text...and that i cannot change . These are word forms. The rest of the related data remains as fields of a record in a db table. Just this one field will point to a folder on the server.