https://es.wikieducator.org/index.php?title=Usuario:Lmorillas/desarrollo_web_servidor/php/ficheros&feed=atom&action=history
Usuario:Lmorillas/desarrollo web servidor/php/ficheros - Historial de revisiones
2024-03-29T13:37:22Z
Historial de revisiones para esta página en el wiki
MediaWiki 1.23.14
https://es.wikieducator.org/index.php?title=Usuario:Lmorillas/desarrollo_web_servidor/php/ficheros&diff=14269&oldid=prev
Lmorillas en 09:18 21 ene 2014
2014-01-21T09:18:06Z
<p></p>
<table class='diff diff-contentalign-left'>
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr style='vertical-align: top;'>
<td colspan='2' style="background-color: white; color:black; text-align: center;">← Revisión anterior</td>
<td colspan='2' style="background-color: white; color:black; text-align: center;">Revisión de 09:18 21 ene 2014</td>
</tr><tr><td colspan="2" class="diff-lineno">Línea 6:</td>
<td colspan="2" class="diff-lineno">Línea 6:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>|Title=Documentación}}</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>|Title=Documentación}}</div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">== Abrir archivos ==</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"><source lang="php"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"><?php</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">if ( !($fp = fopen("myfile.txt", "r") ) )</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">exit("Unable to open the input file.");</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">?></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></source></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>== Lectura de un archivo ==</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>== Lectura de un archivo ==</div></td></tr>
</table>
Lmorillas
https://es.wikieducator.org/index.php?title=Usuario:Lmorillas/desarrollo_web_servidor/php/ficheros&diff=14268&oldid=prev
Lmorillas: Página creada con '{{MiTitulo|Ficheros con PHP}} {{Objetivo| ; Funciones del sistema de ficheros : http://es1.php.net/manual/es/book.filesystem.php |Title=Documentación}} == Lectura de un arch…'
2014-01-21T09:16:46Z
<p>Página creada con '{{MiTitulo|Ficheros con PHP}} {{Objetivo| ; Funciones del sistema de ficheros : http://es1.php.net/manual/es/book.filesystem.php |Title=Documentación}} == Lectura de un arch…'</p>
<p><b>Página nueva</b></p><div>{{MiTitulo|Ficheros con PHP}}<br />
<br />
{{Objetivo|<br />
; Funciones del sistema de ficheros<br />
: http://es1.php.net/manual/es/book.filesystem.php<br />
<br />
|Title=Documentación}}<br />
<br />
== Lectura de un archivo ==<br />
<source lang="php"><br />
<?php<br />
// poner el contenido de un fichero en una cadena<br />
$nombre_fichero = "/usr/local/algo.txt";<br />
$gestor = fopen($nombre_fichero, "r");<br />
$contenido = fread($gestor, filesize($nombre_fichero));<br />
fclose($gestor);<br />
?><br />
</source><br />
<br />
<br />
== Escritura en archivo ==<br />
<source lang="php"><br />
<?php<br />
$fp = fopen('data.txt', 'w');<br />
fwrite($fp, '1');<br />
fwrite($fp, '23');<br />
fclose($fp);<br />
<br />
// ¡el contenido de 'data.txt' ahora es 123 y no 23!<br />
?><br />
</source><br />
<br />
<br />
== Archivos csv ==<br />
* http://es1.php.net/manual/es/function.fgetcsv.php<br />
* http://es1.php.net/manual/es/function.fputcsv.php<br />
<br />
=== Lectura ===<br />
<source lang="php"><br />
<?php<br />
$fila = 1;<br />
if (($gestor = fopen("test.csv", "r")) !== FALSE) {<br />
while (($datos = fgetcsv($gestor, 1000, ",")) !== FALSE) {<br />
$numero = count($datos);<br />
echo "<p> $numero de campos en la línea $fila: <br /></p>\n";<br />
$fila++;<br />
for ($c=0; $c < $numero; $c++) {<br />
echo $datos[$c] . "<br />\n";<br />
}<br />
}<br />
fclose($gestor);<br />
}<br />
?><br />
</source><br />
<br />
=== Escritura ===<br />
<source lang="php"><br />
<?php<br />
<br />
$lista = array (<br />
array('aaa', 'bbb', 'ccc', 'dddd'),<br />
array('123', '456', '789'),<br />
array('"aaa"', '"bbb"')<br />
);<br />
<br />
$fp = fopen('archivo.csv', 'w');<br />
<br />
foreach ($lista as $campos) {<br />
fputcsv($fp, $campos);<br />
}<br />
<br />
fclose($fp);<br />
?><br />
</source><br />
<br />
=== Devuelve archivo csv ===<br />
<source lang="php"><br />
<?php<br />
<br />
header('Content-Type: application/excel');<br />
header('Content-Disposition: attachment; filename="sample.csv"');<br />
$data = array(<br />
'aaa,bbb,ccc,dddd',<br />
'123,456,789',<br />
'"aaa","bbb"'<br />
);<br />
<br />
$fp = fopen('php://output', 'w');<br />
foreach ( $data as $line ) {<br />
$val = explode(",", $line);<br />
fputcsv($fp, $val);<br />
}<br />
fclose($fp);<br />
?><br />
</source></div>
Lmorillas