Underc0de - La Casa de los Informáticos

Foros Generales => Dudas y pedidos generales => Mensaje iniciado por: arthusu en Agosto 04, 2011, 07:05:35 PM

Título: [SOLUCIONADO] [Taller PHP] Duda taller php 2 ejercicio 3
Publicado por: arthusu en Agosto 04, 2011, 07:05:35 PM
Bueno lo que me pasa es que me salta este error:
Parse error: syntax error, unexpected ';', expecting ')' in C:\AppServ\www\taller\taller2_prueba3.php on line 12
Objetivo de la actividad:
Hacer un script que cree un directorio en donde adentro se generen 3 archivos
de texto (uno, dos y tres) para posteriormente forzar la eliminación del mismo
directorio.

no se que hacer y pues estoy aprendiendo php apenas espero me ayuden, aqui va el codigo html y php:

HTML: taller2_prueba3.html
Código (html5) [Seleccionar]
<!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>Generar archivos</title>
</head>

<body>
<form action="taller2_prueba3.php" method="post">
Crear archivos y elimarlos juntos con carpeta: <br />
<input type="submit" name="generar" value="Generar" />
</form>
</body>
</html>


PHP: taller2_prueba3.php
Código (php) [Seleccionar]
<!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>Documento sin t&iacute;tulo</title>
</head>

<body>
<?php
mkdir
('archivos/');
$tresarchivos= array (
$tresarchivos[0] = fopen('uno.txt','w+');
$tresarchivos[1] = fopen('dos.txt''w+'); 
$tresarchivos[2] = fopen('tres.txt''w+');
);
copy('$tresarchivos''archivos/');
if(
$tresarchivos == false){
die (
'No se han podido crear los archivos');}
?>

</body>
</html>


Espero me puedan ayudar, gracias de antemano y un saludo a todos!
Título: Re:[Taller PHP]Duda taller php 2 ejercicio 3
Publicado por: ~ Yoya ~ en Agosto 04, 2011, 07:57:48 PM
Buenas, el problema esta en la sintaxis que usas para crear arrays.

Código (php) [Seleccionar]
$tresarchivos= array (
$tresarchivos[0] = fopen('uno.txt','w+');
$tresarchivos[1] = fopen('dos.txt', 'w+');
$tresarchivos[2] = fopen('tres.txt', 'w+');
);


Con esto bastaría:
Código (php) [Seleccionar]
$tresarchivos= array ();
$tresarchivos[0] = fopen('uno.txt','w+');
$tresarchivos[1] = fopen('dos.txt', 'w+');
$tresarchivos[2] = fopen('tres.txt', 'w+');


Otras formas:
Código (php) [Seleccionar]

$tresarchivos[0] = fopen('uno.txt','w+');
$tresarchivos[1] = fopen('dos.txt', 'w+');
$tresarchivos[2] = fopen('tres.txt', 'w+');


Código (php) [Seleccionar]

$tresarchivos[] = fopen('uno.txt','w+');
$tresarchivos[] = fopen('dos.txt', 'w+');
$tresarchivos[] = fopen('tres.txt', 'w+');


Todas son validas.



Ahora no le puedes pasar como primer argumento a la función copy() un array como lo estas haciendo. Deberas recorrer el array utilizando foreach(), while() o for().

Saludos.
Título: Re:[Taller PHP]Duda taller php 2 ejercicio 3
Publicado por: arthusu en Agosto 04, 2011, 08:03:46 PM
@~ Yoya ~

Muchisimas gracias, ahora mismo modificare y gracias por lo de copy() por decirme que cree un buble thanks no lo sabia :P :D
Título: Re:[Taller PHP]Duda taller php 2 ejercicio 3
Publicado por: DarkStreaM en Agosto 04, 2011, 10:58:12 PM
Y no es mas fácil asi?

Código (php) [Seleccionar]
$tresarchivos= array (fopen('uno.txt','w+'),fopen('dos.txt', 'w+'),fopen('tres.txt', 'w+'));
Título: Re:[Taller PHP]Duda taller php 2 ejercicio 3
Publicado por: arthusu en Agosto 05, 2011, 02:00:42 AM
El codigo me quedo asi, paa los que andan en talleres y tienen el mismo problema:

HTML:
Código (html5) [Seleccionar]
<!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>Generar archivos</title>
</head>

<body>
<form action="taller2_prueba3.php" method="post">
Crear archivos y elimarlos juntos con carpeta: <br />
<input type="submit" name="generar" value="Generar" />
</form>
</body>
</html>


PHP:
Código (php) [Seleccionar]
<!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>Documento sin t&iacute;tulo</title>
</head>

<body>
<?php
mkdir
('archivos/');
$tresarchivos = array('uno''dos''tres');
foreach (
$tresarchivos as $archivo) {
if (!
fopen('archivos/'.$archivo.'.txt''w+')) die('Oh no... No pude crear '.$archivo.'.txt');
}
echo 
"Archivos Creados.\n";
$archivos = array();
foreach (
$archivos as $archivo) {
if (!
fclose($archivo)) die('Oh no... No pude cerrar un archivo');
}
echo 
"Archivos Cerrados.<br />";
$dir scandir('archivos/');
$numfiles count($dir);
for(
$i 0$i<$numfiles$i++)
{
if(@
unlink('archivos/'.$dir[$i]))
{
echo 
'El archivo '.$dir[$i].' fue borrado correctamente. <br />';
}
}
rmdir('archivos/');
echo 
"Carpeta eliminada correctamente. <br />"
?>

</body>
</html>


Gracias por todo a th3-822 que me brindo un poco de su ayuda