文章目录[隐藏]
例如目前有个1.html文件,想用PHP程序把1.html里面的任意内容修改掉,然后保存
1.html 例如里面的内容有
11111111111222222222abc222222333333333333333333444444444444
就是想用PHP把1.html源码全部读取出来放在一个编辑框内,然后可以在里面任意修改内容后 ,点保存就保存起来。这个怎么实现?有点类似DEDE后台的模版文件修改那样,不过没有那么复杂。谢谢指教!
回复讨论(解决方案)
??完成後,提交?容?,需要把原?的文件路?也提交,
然後服?端直接file_put_contents(文件名,文件?容,true); 就可以了。
??完成後,提交?容?,需要把原?的文件路?也提交,
然後服?端直接file_put_contents(文件名,文件?容,true); 就可以了。
前面具体怎么调用??有没有整个完成的流程代码?新手!不太理解!谢谢指导!
http://www.example.com/index.php?file=1.html
然後在同目?下?建一?1.html
index.php
<?php$file = isset($_REQUEST['file'])? $_REQUEST['file'] : '';if($file=='' || file_exists($file)==false){ echo 'file not exists'; exit();}$content = isset($_POST['content'])? $_POST['content'] : '';if($content!=''){ // 有修改 file_put_contents($file, $content, true);}?> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <span>@本文来*源gaodai#ma#com搞*!代#%^码$网*</span><textarea>搞gaodaima代码</textarea><title> New Document </title> <body> <p>文件?容</p> <p><textarea name="content" style="width:500px;height:300px"><?php echo file_get_contents($file); ?></textarea></p>