In PHP, this is how you can read the contents of file so you can display it in a form and write the contents of a web form to a file. You can add more complex read and write operations as desired but this is the basic way to do file IO.
// get body
$path2file = SITE_ROOT.”/xml/doc_” . $doc_id . “.php”;
$fp = fopen($path2file, ‘r’) or die (‘Could not open $path2file for reading.’);
$data[‘doc_body’] = fread($fp, filesize($path2file));
fclose($fp);
// write body
$path2file = SITE_ROOT.”/xml/doc_” . $doc_id . “.php”;
$fh = fopen($path2file, “w”) or die (‘Could not open file for writing.’);
fwrite ($fh, $form_data[‘doc_body’]);
fclose($fh);
In PHP, this is how you can read the contents of file so you can display it in a form and write the contents of a web form to a file. You can add more complex read and write operations as desired but this is the basic way to do file IO.
// get body
$path2file = SITE_ROOT.”/xml/doc_” . $doc_id . “.php”;
$fp = fopen($path2file, ‘r’) or die (‘Could not open $path2file for reading.’);
$data[‘doc_body’] = fread($fp, filesize($path2file));
fclose($fp);
// write body
$path2file = SITE_ROOT.”/xml/doc_” . $doc_id . “.php”;
$fh = fopen($path2file, “w”) or die (‘Could not open file for writing.’);
fwrite ($fh, $form_data[‘doc_body’]);
fclose($fh);