PHP - Input type="file" con arreglo (upload)

 
Vista:
sin imagen de perfil

Input type="file" con arreglo (upload)

Publicado por Ariel Olea (2 intervenciones) el 17/06/2009 18:55:48
Saludos a todos.

Aquí les pongo un código para poder subir (upload) más de un archivo mediante un input type="file".
Esto lo hice porque necesitaba subir varios upload usando jquery.
El jquery me permite subir más de un archivo, pero llegaba hasta el momento de subir los archivos a una carpeta del servidor.

Espero que les sirva este código, de algo puede ser útil.

Saludos

index.php
========

<form name="frm_visita_ing" method="post" action="graba.php" enctype="multipart/form-data">

<input name="archivo[]" id="archivo" type="file" />
<input name="archivo[]" id="archivo" type="file" />
<input name="archivo[]" id="archivo" type="file" />

<input type="submit" name="Grabar" value="Grabar" />

</form>

graba.php
========
<?
header("Cache-Control: no-store, no-cache, must-revalidate");

$path="/var/www/html/pagina/";
$i=0;
$archivos=array();
foreach($_FILES['archivo']['name'] as $id=>$file_upload){

$i++;
$realname = $_FILES['archivo']['name'][ $id ];//saber el nombre del archivo
$pos = strrpos($realname, ".");
$ext=substr($realname,$pos+1,5);

$file=$i.".".$ext;
$archivos[]=$file;

if (!file_exists($path."doctos/"))
mkdir ($path."doctos", 0770) ;

$file="$path"."doctos/$file";
move_uploaded_file($_FILES['archivo']['tmp_name'][ $id ], $file);

}

?>

<!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=iso-8859-1" />
<title>Archivos subidos</title>
</head>

<body>
<?
foreach($archivos as $id=>$nombre){
?>
<a href="<? echo "doctos/".$nombre; ?>"><? echo $nombre; ?></a><br />
<?
}
?>
</body>
</html>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

RE:Input type=

Publicado por Gabriel (30 intervenciones) el 20/06/2009 05:36:40
graba.php ========
Warning: Cannot modify header information - headers already sent by (output started at C:AppServwwwupload2.php:11) in C:AppServwwwupload2.php on line 27

Warning: Invalid argument supplied for foreach() in C:AppServwwwupload2.php on line 32
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

RE:Input type=

Publicado por Ariel Olea (2 intervenciones) el 30/06/2009 20:43:31
Prueba quitando la línea "header("Cache-Control: no-store, no-cache, must-revalidate"); "
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar