bssanchez93

[PHP] Editar Archivos - (Bad way)

Jul 11th, 2014
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.43 KB | None | 0 0
  1. <?php
  2. /**
  3.  * @autor: YO xDDDDD
  4.  * Uso: se pasan los parametros por url accion y archivo asi:
  5.  *
  6.  * action=edit&archivo=/ruta/hacia/el/archivo.ext
  7.  *
  8.  * NOTA: Se debe tener en cuenta que el archivo debe tener permisos de escritura
  9.  */
  10.  
  11.  
  12. if ((isset($_POST['btn_func']) && $_POST['btn_func'] == "Guardar") && (isset($_POST['multilinea']) && $_POST['multilinea'] != "") && (isset($_POST['ruta']) && $_POST['ruta'] != "")) {
  13.     $guardar_arc = fopen($_POST['ruta'], 'w');
  14.     if (fwrite($guardar_arc, $_POST['multilinea'])) {
  15.         echo "<span style='color: #0F0;'>Archivo guardado!!!</span>";
  16.     } else {
  17.         echo "<span style='color: #F00;'>No se pudo guardar!!!</span>";
  18.     }
  19. }
  20. ?>
  21.  
  22. <form action = "<?php echo $_SERVER['SCRIPT_NAME']; ?>" method = "post">
  23.     <textarea id = "multilinea" name = "multilinea" style = "width: 95%; height: 150px; resize: none;"><?php
  24.         if (isset($_GET['archivo'], $_GET['action']) && ($_GET['archivo'] != "" && $_GET['action'] == "edit")) {
  25.             $archivo = file_get_contents($_GET['archivo']);
  26.             $archivo = ucfirst($archivo);
  27.             echo htmlentities($archivo);
  28.         }
  29.         ?></textarea>
  30.     <br><input type="text" name="ruta" value="<?php
  31.     if (isset($_GET['archivo']) && $_GET['archivo'] != '') {
  32.         echo $_GET['archivo'];
  33.     }
  34.     ?>" style="width: 50%;">&nbsp;&nbsp;&nbsp;<input type="submit" name="btn_func" id="btn_save" value="Guardar">
  35. </form>
Advertisement
Add Comment
Please, Sign In to add comment