ztealmax Posted December 1, 2006 Share Posted December 1, 2006 Hi if i want to create a new text file and edit it, how do i save it as the title name of that text document?right now i have this script:edit_form.php[code]<form action="edit_process.php" method="post"><textarea rows="25" cols="40" name="content"><?$fn = "news/news.txt";print htmlspecialchars(implode("",file($fn)));?> </textarea><br><input type="submit" value="Change!"> </form>[/code]edit_process.php[code]<?$fn = "news/news.txt";$content = stripslashes($_POST['content']);$fp = fopen($fn,"w") or die ("Error opening file in write mode!");fputs($fp,$content);fclose($fp) or die ("Error closing file!");echo "<meta http-equiv=\"refresh\" content=\"0; url=read.php\" />\n";?>[/code]As you notice i use a predefined name in this, but instead of that i would like to useA title as the save name:for example if i have the edit boxi also would like a title boxand somehow get the titlebox name as the save file nameIs that possible?//cheers Link to comment https://forums.phpfreaks.com/topic/29135-create-a-text-file-and-save-it-as-title-name/ Share on other sites More sharing options...
keeB Posted December 1, 2006 Share Posted December 1, 2006 Consider you have a textbox named "title" and it is posted to edit_process.php via $_POST['title']code:[code=php:0]$fn = "news/" . $_POST['title'];$content = stripslashes($_POST['content']);$fp = fopen($fn,"w") or die ("Error opening file in write mode!");[/code]I am pretty sure if the file does not exist, fopen creates it. If not, then you will need to use file_exists and create the file before opening it. Link to comment https://forums.phpfreaks.com/topic/29135-create-a-text-file-and-save-it-as-title-name/#findComment-133579 Share on other sites More sharing options...
ztealmax Posted December 1, 2006 Author Share Posted December 1, 2006 [quote author=keeB link=topic=117014.msg477149#msg477149 date=1164998880]Consider you have a textbox named "title" and it is posted to edit_process.php via $_POST['title']code:[code=php:0]$fn = "news/" . $_POST['title'];$content = stripslashes($_POST['content']);$fp = fopen($fn,"w") or die ("Error opening file in write mode!");[/code]I am pretty sure if the file does not exist, fopen creates it. If not, then you will need to use file_exists and create the file before opening it.[/quote]okej, ive done this so far:edit_process.php[code]<?$fn = "news/" . $_POST['title'];$content = stripslashes($_POST['content']);$fp = fopen($fn,"w") or die ("Error opening file in write mode!");fputs($fp,$content);fclose($fp) or die ("Error closing file!");echo "<meta http-equiv=\"refresh\" content=\"0; url=read.php\" />\n";?>[/code]edit_form.php[code]<form action="edit_process.php" method="post"><textarea rows="1" cols="40" name="title">TITLE</textarea><textarea rows="25" cols="40" name="content"><?$fn = "news/news.txt";print htmlspecialchars(implode("",file($fn)));?> </textarea><br><input type="submit" value="Change!"> </form>[/code]how ever what should it say in [b]$fn = ""[/b] in edit_form.phpand how do i add .txt to the title name?For example if i name the file testar, now it saves it as testar but i would like it to save it as testar.txt//Thanx :) Link to comment https://forums.phpfreaks.com/topic/29135-create-a-text-file-and-save-it-as-title-name/#findComment-133596 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.