ztealmax Posted December 14, 2006 Share Posted December 14, 2006 hi :)If i want to edit a specific file and open it for edit in this way:edit.php?text=news/finall test.txthow would i implement that in this script?edit.php[CODE]<form action="edit_process.php" method="post"><textarea rows="1" cols="40" name="title"></textarea><textarea rows="25" cols="40" name="content"><?$fn = "news/";print htmlspecialchars(implode("",file($fn)));?> </textarea><br><input type="submit" value="Change!"> </form>[/CODE]edit_process.php[code]<?$fn = "news/Update" . $_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]Thanx//Martin Link to comment https://forums.phpfreaks.com/topic/30628-if-i-want-to-edit-a-specific-file-and-open-it-for-edit-in-php/ Share on other sites More sharing options...
uktrips007 Posted December 14, 2006 Share Posted December 14, 2006 [code]$fp = fopen($fn,"w") or die ("Error opening file in write mode!");[/code]open this file in append mode in order to edit it.[code]$fp = fopen($fn,"a+") or die ("Error opening file in write mode!");[/code] Link to comment https://forums.phpfreaks.com/topic/30628-if-i-want-to-edit-a-specific-file-and-open-it-for-edit-in-php/#findComment-141059 Share on other sites More sharing options...
ztealmax Posted December 14, 2006 Author Share Posted December 14, 2006 Hi thanx, i cant get it to work? have i forgoten anything?I want it to open it for edit with this line in the address bar:edit.php?id=news/nameoffile.txtbut not sure if i done something wrong in this? Link to comment https://forums.phpfreaks.com/topic/30628-if-i-want-to-edit-a-specific-file-and-open-it-for-edit-in-php/#findComment-141081 Share on other sites More sharing options...
ztealmax Posted December 15, 2006 Author Share Posted December 15, 2006 Unresolved, anyone can help me with this`?>>thanx<< Link to comment https://forums.phpfreaks.com/topic/30628-if-i-want-to-edit-a-specific-file-and-open-it-for-edit-in-php/#findComment-141610 Share on other sites More sharing options...
trq Posted December 15, 2006 Share Posted December 15, 2006 [quote]i cant get it to work?[/quote]Explain what you meen by this? Are you seeing any errors? What are they?Also, you might post your most recnet code. Link to comment https://forums.phpfreaks.com/topic/30628-if-i-want-to-edit-a-specific-file-and-open-it-for-edit-in-php/#findComment-141640 Share on other sites More sharing options...
ztealmax Posted December 15, 2006 Author Share Posted December 15, 2006 edit_form.php[code]<form action="edit_process.php" method="post"><textarea rows="1" cols="40" name="title"></textarea><textarea rows="25" cols="40" name="content"><?$fn = "news/";print htmlspecialchars(implode("",file($fn)));?> </textarea><br><input type="submit" value="Change!"> </form>[/code]edit_process.php[code]<?$fn = "news/" . $_POST['title'];$content = stripslashes($_POST['content']);$fp = fopen($fn,"a+") 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]no errors att all when i try to open it this way[b]edit_form.php/?text=news/finall%20test[/b]just a blank edit form//Martin Link to comment https://forums.phpfreaks.com/topic/30628-if-i-want-to-edit-a-specific-file-and-open-it-for-edit-in-php/#findComment-141691 Share on other sites More sharing options...
ztealmax Posted December 16, 2006 Author Share Posted December 16, 2006 Anyone got any idea what im doing wrong? ;)//Thanx all Link to comment https://forums.phpfreaks.com/topic/30628-if-i-want-to-edit-a-specific-file-and-open-it-for-edit-in-php/#findComment-142299 Share on other sites More sharing options...
Albright Posted December 16, 2006 Share Posted December 16, 2006 HUUUUUUUUUUUUUUUUUUUUUUUUUUUUGE SECURITY ISSUES HERE! If you're not careful, you could make it so anyone could edit [i]any file[/i] on your server. I would strongly [i]not[/i] recommend ever implementing something like this.Anyway... Your edit form is probably blank because it looks like you're trying to insert the contents of an invalid file; that is, a directory, just named "news/". Try setting $fn equal to a valid file. Or better yet, never implement something like this in the first place. Link to comment https://forums.phpfreaks.com/topic/30628-if-i-want-to-edit-a-specific-file-and-open-it-for-edit-in-php/#findComment-142313 Share on other sites More sharing options...
ztealmax Posted December 16, 2006 Author Share Posted December 16, 2006 [quote] author=Albright link=topic=118593.msg486019#msg486019 date=1166260223]HUUUUUUUUUUUUUUUUUUUUUUUUUUUUGE SECURITY ISSUES HERE! If you're not careful, you could make it so anyone could edit [i]any file[/i] on your server. I would strongly [i]not[/i] recommend ever implementing something like this.Anyway... Your edit form is probably blank because it looks like you're trying to insert the contents of an invalid file; that is, a directory, just named "news/". Try setting $fn equal to a valid file. Or better yet, never implement something like this in the first place.[/quote]well not quite, im adding a authenticate thingy later :)well i was hopping it was possible to open the file like this:"edit_form.php?text=news/" Like in my read.php script[code]<?PHP require_once("theme.php");?><?php// set file to read$file = $_GET['text'];// open file $fh = fopen($file, 'r') /*or die('Could not open file!')*/;// read file contents$data = fread($fh, filesize($file)) /*or die('Could not read file!')*/;// close file fclose($fh); // print file contents ?><DIV class=spacer> <TABLE cellSpacing=0 cellPadding=0> <TR> <TD class=captiontopleft><IMG style="DISPLAY: block" height=4 alt="" src="images/blank.gif" width=21></TD> <TD class=captiontopmiddle><IMG style="DISPLAY: block" height=4 alt="" src="images/blank.gif" width=1></TD> <TD class=captiontopright><IMG style="DISPLAY: block" height=4 alt="" src="images/blank.gif" width=8></TD></TR></TABLE> <TABLE cellSpacing=0 cellPadding=0> <TR> <TD class=captionleft><IMG style="DISPLAY: block" height=17 alt="" src="images/blank.gif" width=21></TD> <TD class=captionbar style="WHITE-SPACE: nowrap"><? echo $file;?></TD> <TD class=captionend><IMG style="DISPLAY: block" height=17 alt="" src="images/blank.gif" width=21></TD> <TD class=captionmain><IMG style="DISPLAY: block" height=17 alt="" src="images/blank.gif" width=1></TD> <TD class=captionright><IMG style="DISPLAY: block" height=17 alt="" src="images/blank.gif" width=9></TD></TR></TABLE> <TABLE cellSpacing=0 cellPadding=0> <TR> <TD class=bodyleft><IMG style="DISPLAY: block" height=1 alt="" src="images/blank.gif" width=3></TD> <TD class=bodymain><DIV class="smallblacktext"><pre><? echo $data;?></DIV></pre><DIV class=alttd style="TEXT-ALIGN: right"><? echo "Posted: " . date ("F d Y H:i:s.", filemtime($file)); ?> </DIV></TD> <TD class=bodyright><IMG style="DISPLAY: block" height=1 alt="" src="images/blank.gif" width=3></TD></TR></TABLE> <TABLE cellSpacing=0 cellPadding=0> <TR> <TD class=bottomleft><IMG style="DISPLAY: block" height=8 alt="" src="images/blank.gif" width=12></TD> <TD class=bottommain><IMG style="DISPLAY: block" height=8 alt="" src="images/blank.gif" width=1></TD> <TD class=bottomright><IMG style="DISPLAY: block" height=8 alt="" src="images/blank.gif" width=12></TD></TR></TABLE></DIV>[/code]so what news i select later in a dropdown menu i can link it to that so it opens it for editing, you understand what the hell im talking about ;)//Thanx Link to comment https://forums.phpfreaks.com/topic/30628-if-i-want-to-edit-a-specific-file-and-open-it-for-edit-in-php/#findComment-142323 Share on other sites More sharing options...
ztealmax Posted December 17, 2006 Author Share Posted December 17, 2006 This is still unsolved guys .. .;) Link to comment https://forums.phpfreaks.com/topic/30628-if-i-want-to-edit-a-specific-file-and-open-it-for-edit-in-php/#findComment-142816 Share on other sites More sharing options...
ztealmax Posted December 17, 2006 Author Share Posted December 17, 2006 tried this now:edit.php[code]<?PHP require_once("theme.php");?><form action="edit_process.php" method="post"><textarea rows="1" cols="40" name="title"></textarea><textarea rows="25" cols="40" name="content"><?php// set file to read$file = $_GET['text'];// open file $fn = "news/";print htmlspecialchars(implode("",file($fn)));// read file contents$data = fread($fn, filesize($file)) /*or die('Could not read file!')*/;// close file fclose($fn); // print file contents ?></textarea><br><input type="submit" value="Change!"> </form>[/code]edit_process.php[code]<?$fn = "news/" . $_POST['title'];$content = stripslashes($_POST['content']);$fp = fopen($fn,"a+") 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]well shortly i can get it working.. Link to comment https://forums.phpfreaks.com/topic/30628-if-i-want-to-edit-a-specific-file-and-open-it-for-edit-in-php/#findComment-142923 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.