[SOLUCIONADO] [Taller PHP] Duda taller php 2 ejercicio 3

Iniciado por arthusu, Agosto 04, 2011, 07:05:35 PM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Agosto 04, 2011, 07:05:35 PM Ultima modificación: Julio 14, 2014, 12:43:10 AM por Expermicid
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
<!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
<!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!
Pentest - Hacking & Security Services

Contact me: No tienes permitido ver enlaces. Registrate o Entra a tu cuenta

Buenas, el problema esta en la sintaxis que usas para crear arrays.

Código: php
$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
$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

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


Código: php

$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.
Mi madre me dijo que estoy destinado a ser pobre toda la vida.
Engineering is the art of balancing the benefits and drawbacks of any approach.

@~ Yoya ~

Muchisimas gracias, ahora mismo modificare y gracias por lo de copy() por decirme que cree un buble thanks no lo sabia :P :D
Pentest - Hacking & Security Services

Contact me: No tienes permitido ver enlaces. Registrate o Entra a tu cuenta

Y no es mas fácil asi?

Código: php
$tresarchivos= array (fopen('uno.txt','w+'),fopen('dos.txt', 'w+'),fopen('tres.txt', 'w+'));

El codigo me quedo asi, paa los que andan en talleres y tienen el mismo problema:

HTML:
Código: html5
<!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
<!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
Pentest - Hacking & Security Services

Contact me: No tienes permitido ver enlaces. Registrate o Entra a tu cuenta