note 34085 added to function.fopen
| From: | waterboy at rack1 dot php dot net | Date: | Tue, 15 Jul 2003 22:41:42 +0000 |
| Subject: | note 34085 added to function.fopen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-52156@lists.php.net to get a copy of this message | ||
<?PHP
$self = basename($_SERVER["PHP_SELF"]);
if (isset($_POST["action"])) {
$action = $_POST["action"];
} elseif ($_GET["action"]) {
$action = $_GET["action"];
} else {
$action = "default";
}
function separate_fields($aVar) {
return explode(";;", $aVar);
}
function import_file($aFile) {
return join("", file($aFile));
/*
$fd = fopen($aFile, "r");
$returnableVar = fread ($fd, filesize($aFile));
fclose($fd);
return $returnableVar;
*/
}
function write_fields_to_file($aFile) {
// this writes the post fields to the given file, and backs up the old one (only one backup)
global $fieldSeparator, $lineSeparator;
$forChange = import_file($aFile) . ";;" . $_POST["TEST"];
$fp=fopen($aFile, "w");
fwrite($fp, $forChange);
fclose($fp);
}
echo "<HTML>";
$fileToImport = "test.txt";
if($action == "change") {
write_fields_to_file($fileToImport);
}
echo "<FORM ACTION=\"" . $self . "\" METHOD=\"post\">"
. chr(10);
$importedFields = separate_fields(import_file($fileToImport));
foreach($importedFields as $value)
echo $value;
echo "<INPUT TYPE=\"hidden\" NAME=\"action\"
VALUE=\"change\">";
echo "<INPUT TYPE=\"text\" NAME=\"TEST\">";
echo "<INPUT TYPE=\"SUBMIT\">";
echo "</FORM>" . chr(10);
echo date("M d, y h:i:s");
echo "</BODY></HTML>";
?>
<waterboy> this is a pseudo snippet of the code I'm trying to figure out.
<SeerHome> what version of php do you run?
<waterboy> 4.2.3
<SeerHome> replace the import_file() code by this line
<SeerHome> return join('',file($aFile));
<waterboy> IT WORKS!!!, so what's the deal?
<SeerHome> you need to add clearstatcache();
<SeerHome> if you do multiple operations to the same file
<SeerHome> at least it seems to be like that
<SeerHome> it's your filesize() which breaks it logically see
<SeerHome> filesize() is a stat-info since you write to it the size changes
<SeerHome> but the value php uses is the same value for filesize
<SeerHome> because it doesn't rerun the check
<waterboy> hey, thanks for all the help! GREATLY appreciated.
<SeerHome> i have to kill some time ;) wouldn't try this on php3
----
Manual Page -- http://www.php.net/manual/en/function.fopen.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34085
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34085&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34085&report=yes