Вообщем проблема такая:
пишу wysiwyg-редактор. После набора текста нужно сохранить. Структура папки, куда сохранять, такая:
- [Dir_Main]
- [_data]
- [_images]
- [_test]
Если в корне нет файла index.htm, то сохранить нужно в корень Dir_Main, если он есть, то в папку _data. Скрипт проверял десятки раз, но он сохраняет только в корень, т.е. перезаписывает index.htm.
Скрипт сохранения:
CODE ( text):
скопировать код в буфер обмена
if(isset($sfile)) { //------------------------------------------------------------- $head_i = "<html> rn"; $head_i .= "<head> rn"; $head_i .= "<title>"; $head_o = "</title> rn"; $head_o .= "<meta http-equiv='Content-Type' content='text/html; charset=windows-1251'> rn"; $head_o .= "<style type='text/css'> rn"; $head_o .= "body {background-color:#FFFFFF;} rn"; $head_o .= "a:link { color:#000000; text-decoration:none; } rn"; $head_o .= "a:active { color:#000000; text-decoration:none; } rn"; $head_o .= "a:visited {color:#AAAAAA; text-decoration:none; } rn"; $head_o .= "a:hover { color:#0000FF; text-decoration:underline; } rn"; $head_o .= "</style> rn"; $head_o .= "</head> rn"; $head_o .= "<body> rn"; $foot_o = "rn</body> rn"; $foot_o .= "</html>"; //------------------------------------------------------------- $path = NULL; $file_1 = "../_base/".$_GET['ad']."/index.html"; $file_2 = "../_base/".$_GET['ad']."/index.htm"; //------------------------------------------------------------- if(!file_exists($file_1) or !file_exists($file_2)) { $path = "../_base/".$_GET['ad']."/"; } else { $path = "../_base/".$_GET['ad']."/_data/"; } //------------------------------------------------------------- $nfile = format($nfile); if(!valid_str($nfile)) {error("Error in file name.");} //------------------------------------------------------------- $fnew = fopen($path.$nfile, "w"); if(!file_exists($path.$nfile)) { print "<script>alert('File exist.')</script>"; } fwrite($fnew, $head_i.$ttl.$head_o.$confile.$foot_o); fclose($fnew); //------------------------------------------------------------- }
Форма разметки:
CODE ( text):
скопировать код в буфер обмена
<?php include("./_include/save.php"); ?> <table align="left" border="0" cellspacing="0" width="70%" class="nav_table"> <tr> <td align="right" class="td_left" nowrap>File Name:</td> <td align="left"><input name="nfile" type="text" class="text" id="nfile" value="index.html" size="15"></td> <td align="right" class="td_left" nowrap>Title:</td> <td align="left"><input name="ttl" type="text" class="text" id="ttl" size="20"></td> <td align="right" class="td_left" nowrap>Dir "Data":</td> <td align="left"> <select class="select"> <?php PrintFile();?> </select> </td> </tr> </table> <input type="submit" value="Save File" class="button" name="sfile" style="width:80px;">
|