[Php-avanzado] consulta

Maia C maiacordero en gmail.com
Mie Oct 6 09:42:35 ART 2010


Holis.

Lee el directorio, lee los archivos pero NO los escribe T_T

alguna idea?

gracias :)


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
>     "http://www.w3.org/TR/html4/loose.dtd">
> <html>
>     <head>
>         <title> class3 ejer4 </title>
>     </head>
>     <body>
> <?php
> //leo el directorio
>         $dir = scandir("./cursophp2",1);
>
>         if (!isset($_POST['btnEnviar'])) {
> ?>
>         <form action="class3ejer4" method="post" name="ejer4">
>             <label> Seleccionar archivo </label>
>             <select name="archivo" onchange="document.ejer4.submit();">
> <?php
>             foreach ($dir as $key => $valor) {
>                 if (($valor != ".") && ($valor != "..")) {
>                     print '<option value="'.$key.'"';
> //Si el elemento que se agrega es el previamente seleccionado se marca como
> selected
>                     if ( intval($_POST['archivo'] ) == $key )
>                         print ' selected="selected"';
>                     print '>'.$valor.'</option>';
>                 }
>             }
> ?>
>             </select>
>             <br><br>
>         <?php
>             $arc = $dir[$_POST['archivo']];
>             $ruta = './cursophp2/'.$arc;
>             if (file_exists($ruta))
>                 $fp_arch = fopen($ruta,"r");
> ?>
>             <label> Texto del archivo: </label><br>
>             <textarea name="txtTexto"><?php if (file_exists($ruta)) {
>                                             while (!feof($fp_arch)) { print
> fgets($fp_arch); } }
>                                             else { print "archivo no
> cargado"; } ?></textarea>
>             <br><br>
>             <input type="submit" name="btnEnviar" value="Enviar">
>         </form>
> <?php
>             fclose($fp_arch);
>         }else {
> print $ruta; //no tiene valor entonces la tengo que volver a cargar
> //porque pierde el valor asignado anteriormente?
>             $arc = $dir[$_POST['archivo']];
>             $ruta = './cursophp2/'.$arc;
> print $ruta;
>             if (file_exists($ruta))
>                 $fp_new = fopen( $ruta, "w+" );
>
>             $res = fwrite( $fp_new, $_POST['txtTexto'] );
>             if ($res === false) {
>                 print "<br>ERROR NO SE PUDO ESCRIBIR EL ARCHIVO<br>";
>             } else {
>                 print "<br> Datos escritos correctamente<br>";
>             }
>             fclose($fp_new);
>         }
> ?>
>     </body>
> </html>
>
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: http://www3.fi.mdp.edu.ar/pipermail/php-avanzado/attachments/20101006/f842da71/attachment.htm 


Más información sobre la lista de distribución Php-avanzado