I'm creating something that requires I write to .txt files without overwriting previous information.
The written-in information will be HTML, and should be added above previous information. Any idea how to do that? Thanks!
Help Writing to Flat Files
Moderator: General Moderators
- roninblade
- Forum Newbie
- Posts: 21
- Joined: Thu Jun 13, 2002 7:12 pm
Awesome. Is there a way to write to a specific part of the .txt file only?
For instance:
I have three articles, each with three different tables per entry: one with a picture, one with a name, one with a description. How would I edit ONLY the description of a specific name/pic/description or a specific entry?
Here's an example URL:
http://www.aoe2.com/!scripts/filesubmission/
See how I have three different fields? The form up top, the image box on the left and the description on the right?
When I select a map, I want it's description to come up, and I want to be able to add/edit a picture of the map. Then, when I edit any of those fields, I want the edit to go to a .txt file that contains ALL the other maps on it.
How?
For instance:
I have three articles, each with three different tables per entry: one with a picture, one with a name, one with a description. How would I edit ONLY the description of a specific name/pic/description or a specific entry?
Here's an example URL:
http://www.aoe2.com/!scripts/filesubmission/
See how I have three different fields? The form up top, the image box on the left and the description on the right?
When I select a map, I want it's description to come up, and I want to be able to add/edit a picture of the map. Then, when I edit any of those fields, I want the edit to go to a .txt file that contains ALL the other maps on it.
How?
- roninblade
- Forum Newbie
- Posts: 21
- Joined: Thu Jun 13, 2002 7:12 pm
- roninblade
- Forum Newbie
- Posts: 21
- Joined: Thu Jun 13, 2002 7:12 pm
uhmmm... maybe you could format your flat file this way :
Picture#Description
Picture#Description
Picture#Description
i'm assuming here that the picture has a unique value. when you want to edit save each line into an array then edit the value of the line you want to change.
a bit something like this
i haven't tested this code, though. but, i hope this helps.
Picture#Description
Picture#Description
Picture#Description
i'm assuming here that the picture has a unique value. when you want to edit save each line into an array then edit the value of the line you want to change.
a bit something like this
Code: Select all
<?php
$ncontents = array();
$file_name = "path/to/your/file.here";
$contents = file($file_name); // save file into an array
foreach($contents as $val) {
$new = explode("#", $val);
if (in_array($your_test_value, $new)) {
// change the value of the new array
$newї0] = "new picture value";
$newї1] = "new description value";
}
$ncontentsїcount($ncontents)] = implode("#", $new);
}
// save the file
$finalvalue = implode("\n", $ncontents);
$fp = fopen($file_name, "w");
$fresult = fwrite($fp, $finalvalue);
fclose($fp);
?>