urlencode - Cannot make get_file_contents read a cyrillic file names. PHP -
this news.php file:
<form action="create_file.php" method="post" class="form-horizontal"/> <label class="control-label">Заглавие:</label> <div class="controls"> <input name="name" type="text" width="40" class="span6 m-wrap" /> <input type="submit" value="Продължи..." class="btn red"></input> </div> </form>
this create_file.php
<?php $pre_file_name = $_post['name']; $ext = ".txt"; $file_name = $pre_file_name.$ext; fopen($file_name,'w'); ?> <form action="edit_file.php" method="post" class="form-horizontal"/> <label class="control-label">Въведете новината (текст):</label> <div class="controls"> <span class="field"><textarea class="span6 m-wrap" name="edit" cols="1600" rows="10"></textarea></span><p> <input type="hidden" name="file_name" value="<?php echo $file_name; ?>"> <input class="btn red" type="submit" value="Създай!"> </div> </form>
this edit_file.php:
<?php $edit = $_post['edit']; $file_name = $_post['file_name']; $file = fopen($file_name, 'w'); fwrite($file,$edit); fclose($file); header("location: news-success.php"); ?>
delete.php
<?php $file = $_get['name']; unlink($file); header('location: news-delok.php'); ?>
edit.php
<?php $file_name = $_get['name']; $file_read = fopen($file_name,"r"); $contents = fread($file_read, filesize($file_name)); fclose($file_read); ?> <html> <form action="edit_file.php" method="post"> <label>title:</label> <input class="span6 m-wrap" type="text" placeholder="<?php $array = explode(".",$file_name); echo $array[0] ?>" disabled=""><br> <label>text:</label> <textarea class="span6 m-wrap" name="edit" cols="420" rows="10"><?php echo $contents ?></textarea><p> <input type="hidden" name="file_name" value="<?php echo $file_name ?>"> <input class="btn red" type="submit" value="update!"> </form>
how can make script check if there spaces in file name, (for ex. news 1.txt) , replace them + (for ex. news+1.txt)? thank in advance.
for create_file.php following (tested).
for example: if page title "page 1" space between, create page "page_1.txt" adding underscore between. underscore can substituted "+" if required or other valid character.
<?php $ext = ".txt"; $pre_file_name = $_post['name']; $file_name = $pre_file_name.$ext; $file_name = str_replace(" ", "_", $pre_file_name.$ext); fopen($file_name,'w'); ?> <form action="edit_file.php" method="post" class="form-horizontal"/> <label class="control-label">enter new (text):</label> <div class="controls"> <span class="field"><textarea class="span6 m-wrap" name="edit" cols="1600" rows="10"></textarea></span><p> <input type="hidden" name="file_name" value="<?php echo $file_name; ?>"> <input class="btn red" type="submit" value="create one!"> </div> </div> </form>
Comments
Post a Comment