UNIVERSIDAD TECNONOLÓGICA DEL ESTADO DE ZACATECAS
UNIDAD ACADÉMICA DE PINOS
TECNOLOGÍAS DE LA INFORMACIÓN Y COMUNICACIÓN
Materia:
DESARROLLO DE APLICACIONES II.
Tema:
Manejo de Archivos
Nombre completo del Alumnos: Sandra Montoya Reyes, José Jonathan Torres
Castillo.
Grado: 4 Grupo: B
Nombre del Docente : Eloy Contreras De Lira.
Fecha de entrega : 9/10/2013
UNIVERSIDAD TECNONOLÓGICA DEL ESTADO DE ZACATECAS
UNIDAD ACADÉMICA DE PINOS
TECNOLOGÍAS DE LA INFORMACIÓN Y COMUNICACIÓN
EJEMPLOS_CODIGOS
Este código es para abrir el archivo.php.
<? php
$fp=fopen("miarchivo.txt","w");
fputs($fp,("este es mi primer texto escritodesde php");
fclose ($fp);
/?>
Este código es para leer el archivo.php.
<?php
$fp=fopen("pruebas.txt","r");
while (! feof ($fp)){
$linea=fgets ($fp);
echo"<br/>";
}
fclose ($fp);
?>
UNIVERSIDAD TECNONOLÓGICA DEL ESTADO DE ZACATECAS
UNIDAD ACADÉMICA DE PINOS
TECNOLOGÍAS DE LA INFORMACIÓN Y COMUNICACIÓN
INDEX.PHP
En el índex metimos lo que es el diseño de la interfaz metimos
lo que es el código para leer el archivo de texto.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="escritura.php">
<table width="200" border="1">
<tr>
<td>NOMBRE</td>
<td><label for="nombre"></label>
<input type="text" name="nombre" id="nombre" /></td>
</tr>
<tr>
<td>APELLIDO</td>
<td><label for="apellido"></label>
UNIVERSIDAD TECNONOLÓGICA DEL ESTADO DE ZACATECAS
UNIDAD ACADÉMICA DE PINOS
TECNOLOGÍAS DE LA INFORMACIÓN Y COMUNICACIÓN
<input type="text" name="apellido" id="apellido" /></td>
</tr>
<tr>
<td>MATRICULA</td>
<td><label for="matricula"></label>
<input type="text" name="matricula" id="matricula" /></td>
</tr>
<tr>
<td>ESPECIALIDAD</td>
<td><label for="especialidad"></label>
<input type="text" name="especialidad" id="especialidad" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="guardar" id="guardar"
value="GUARDAR" /></td>
</tr>
</table>
</form>
<?php
$fp=fopen("archivo.txt","r");
while(!feof($fp)){
echo fgets($fp)."<br/>";
UNIVERSIDAD TECNONOLÓGICA DEL ESTADO DE ZACATECAS
UNIDAD ACADÉMICA DE PINOS
TECNOLOGÍAS DE LA INFORMACIÓN Y COMUNICACIÓN
}
fclose($fp);
?>
</body>
</html>
ESCRITURA.PHP
Aquí se puso el código de escritura para que se lleve a cabo el
formulario de registro de alumnos.
<?php
$nombre=$_POST['nombre'];
$apellido=$_POST['apellido'];
$matricula=$_POST['matricula'];
$especialidad=$_POST['especialidad'];
$linea=$nombre."t".$apellido."t".$matricula."t".$especialidad."n";
$fp=fopen("archivo.txt","a");
fputs($fp,$linea);
fclose($fp);
?>
UNIVERSIDAD TECNONOLÓGICA DEL ESTADO DE ZACATECAS
UNIDAD ACADÉMICA DE PINOS
TECNOLOGÍAS DE LA INFORMACIÓN Y COMUNICACIÓN

Manejo de archivos

  • 1.
    UNIVERSIDAD TECNONOLÓGICA DELESTADO DE ZACATECAS UNIDAD ACADÉMICA DE PINOS TECNOLOGÍAS DE LA INFORMACIÓN Y COMUNICACIÓN Materia: DESARROLLO DE APLICACIONES II. Tema: Manejo de Archivos Nombre completo del Alumnos: Sandra Montoya Reyes, José Jonathan Torres Castillo. Grado: 4 Grupo: B Nombre del Docente : Eloy Contreras De Lira. Fecha de entrega : 9/10/2013
  • 2.
    UNIVERSIDAD TECNONOLÓGICA DELESTADO DE ZACATECAS UNIDAD ACADÉMICA DE PINOS TECNOLOGÍAS DE LA INFORMACIÓN Y COMUNICACIÓN EJEMPLOS_CODIGOS Este código es para abrir el archivo.php. <? php $fp=fopen("miarchivo.txt","w"); fputs($fp,("este es mi primer texto escritodesde php"); fclose ($fp); /?> Este código es para leer el archivo.php. <?php $fp=fopen("pruebas.txt","r"); while (! feof ($fp)){ $linea=fgets ($fp); echo"<br/>"; } fclose ($fp); ?>
  • 3.
    UNIVERSIDAD TECNONOLÓGICA DELESTADO DE ZACATECAS UNIDAD ACADÉMICA DE PINOS TECNOLOGÍAS DE LA INFORMACIÓN Y COMUNICACIÓN INDEX.PHP En el índex metimos lo que es el diseño de la interfaz metimos lo que es el código para leer el archivo de texto. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form id="form1" name="form1" method="post" action="escritura.php"> <table width="200" border="1"> <tr> <td>NOMBRE</td> <td><label for="nombre"></label> <input type="text" name="nombre" id="nombre" /></td> </tr> <tr> <td>APELLIDO</td> <td><label for="apellido"></label>
  • 4.
    UNIVERSIDAD TECNONOLÓGICA DELESTADO DE ZACATECAS UNIDAD ACADÉMICA DE PINOS TECNOLOGÍAS DE LA INFORMACIÓN Y COMUNICACIÓN <input type="text" name="apellido" id="apellido" /></td> </tr> <tr> <td>MATRICULA</td> <td><label for="matricula"></label> <input type="text" name="matricula" id="matricula" /></td> </tr> <tr> <td>ESPECIALIDAD</td> <td><label for="especialidad"></label> <input type="text" name="especialidad" id="especialidad" /></td> </tr> <tr> <td colspan="2"><input type="submit" name="guardar" id="guardar" value="GUARDAR" /></td> </tr> </table> </form> <?php $fp=fopen("archivo.txt","r"); while(!feof($fp)){ echo fgets($fp)."<br/>";
  • 5.
    UNIVERSIDAD TECNONOLÓGICA DELESTADO DE ZACATECAS UNIDAD ACADÉMICA DE PINOS TECNOLOGÍAS DE LA INFORMACIÓN Y COMUNICACIÓN } fclose($fp); ?> </body> </html> ESCRITURA.PHP Aquí se puso el código de escritura para que se lleve a cabo el formulario de registro de alumnos. <?php $nombre=$_POST['nombre']; $apellido=$_POST['apellido']; $matricula=$_POST['matricula']; $especialidad=$_POST['especialidad']; $linea=$nombre."t".$apellido."t".$matricula."t".$especialidad."n"; $fp=fopen("archivo.txt","a"); fputs($fp,$linea); fclose($fp); ?>
  • 6.
    UNIVERSIDAD TECNONOLÓGICA DELESTADO DE ZACATECAS UNIDAD ACADÉMICA DE PINOS TECNOLOGÍAS DE LA INFORMACIÓN Y COMUNICACIÓN