Page 1 of 1
[SOLVED] fwrite Overwriting Files
Posted: Mon Sep 27, 2004 4:20 pm
by kaYak
I am working with fwrite to write to a file. It must be overwriting the file. Does this code look right?
It grabs the file's contents to display in a text area:
Code: Select all
$template = $_POST['s_temp'] . "_temp.tpl";
$template_file = file_get_contents("/home/research/public_html/smarty/site/templates/$template");
After the person edits the file it is submitted and then grabbed and saved:
Code: Select all
$new_temp_content = $_POST['temp_content'];
$new_temp_content = stripslashes($new_temp_content);
$template_file = $_POST['tf'];
$handle = fopen("/home/research/public_html/smarty/site/templates/$template_file", 'w');
fwrite($handle, $new_temp_content);
fclose($handle);
Could someone tel me if there is something wrong here?
Posted: Mon Sep 27, 2004 4:23 pm
by Joe
What exactly is your problem?. Are you getting errors perhaps?.
Posted: Mon Sep 27, 2004 4:26 pm
by kaYak
Joe wrote:What exactly is your problem?. Are you getting errors perhaps?.
No errors, it's strange. I copied it over from another site and I just changed a few paths, and that's all, so I don't really understand why it's not working.
Posted: Mon Sep 27, 2004 4:34 pm
by Joe
Sorry about the questions but I am just trying to get to the bottom of the problem. When it fails to work what are you resulted in?. A blank screen perhaps?.
Posted: Mon Sep 27, 2004 4:43 pm
by kaYak
Joe wrote:Sorry about the questions but I am just trying to get to the bottom of the problem. When it fails to work what are you resulted in?. A blank screen perhaps?.
I don't mind the questions at all. I am not resulted in a blank screen. All of this is for a CMS, and the file writing should write to a template file. And I have it so it will display a page with the smarty template system which is does successfully, but that isn't the problem. PHP doesn't show any errors or anything, it follows through as though it was working.
Posted: Mon Sep 27, 2004 4:50 pm
by Joe
Try:
Code: Select all
$handle = fopen("/home/research/public_html/smarty/site/templates/".$template_file, 'w+');
Posted: Mon Sep 27, 2004 4:57 pm
by kaYak
Joe wrote:Try:
Code: Select all
$handle = fopen("/home/research/public_html/smarty/site/templates/".$template_file, 'w+');
No, that doesn't work

If you would still like to try and help please do, if not thank you.
Posted: Mon Sep 27, 2004 4:59 pm
by Joe
The line:
$template_file = $_POST['tf'];
Are you sure the form is actually POSTING and that the html form has an element name tf?.
Posted: Mon Sep 27, 2004 5:00 pm
by Joe
Oh and the file mode should be w+ not w.
Posted: Mon Sep 27, 2004 5:12 pm
by kaYak
Joe wrote:The line:
$template_file = $_POST['tf'];
Are you sure the form is actually POSTING and that the html form has an element name tf?.
I fixed it,

. For some reason the form input name was different for the text area's template information so php was grabbing nothing. Thanks for your help!

Posted: Mon Sep 27, 2004 5:13 pm
by Joe
No problem.
