<!--/*
   exemplo de multiplos uploads
   ta2
   tatu@nahumilde.org
   http://nahumilde.org
*/-->
<html>
<head><title>teste upload</title></head>
<body style="background-color:#FFFFFF;">
<div style="line-height:28px;background:#E8FCFF">
<form enctype="multipart/form-data" action="" method="post">
Nome do Evento: <input type="text" size="20" name="evento"><br/>
Data do Evento:<input type="text" size="20" name="data"><br/>
Descri��o: <textarea rows="2" cols="20" name="descricao"></textarea><br/>
<div style="float:left;margin-right:15px;overflow:auto;width:260px;margin-top:10px">
01 - <input name="foto[]" type="file"><br/>
02 - <input name="foto[]" type="file"><br/>
03 - <input name="foto[]" type="file"><br/>
04 - <input name="foto[]" type="file"><br/>
05 - <input name="foto[]" type="file"><br/>
06 - <input name="foto[]" type="file"><br/>
07 - <input name="foto[]" type="file"><br/>
08 - <input name="foto[]" type="file"><br/>
09 - <input name="foto[]" type="file"><br/>
10 - <input name="foto[]" type="file"><br/></div>
<div style="margin-bottom:10px;margin-top:10px">11 - <input name="foto[]" type="file"><br/>
12 - <input name="foto[]" type="file"><br/>
13 - <input name="foto[]" type="file"><br/>
14 - <input name="foto[]" type="file"><br/>
15 - <input name="foto[]" type="file"><br/>
16 - <input name="foto[]" type="file"><br/>
17 - <input name="foto[]" type="file"><br/>
18 - <input name="foto[]" type="file"><br/>
19 - <input name="foto[]" type="file"><br/>
20 - <input name="foto[]" type="file"><br/></div>
<input type="submit" value="Enviar Arquivo">
</form></div>
<div style="background:#D0D0D0;font-family:Verdana;font-size:10px;padding: 4px">
<?
if(count($_POST)){

$conexao=@mysql_connect("localhost","user","password") or die("error connect!");
@mysql_select_db("database",$conexao) or die("can�t find db");

$uploaddir = getcwd(); //seu diretorio atual
$evento=$_POST['evento'];
$data=$_POST['data'];
$descricao=$_POST['descricao'];
$ativo=1;
$sub=$_POST['subscrever'];

if($evento=="") $erros[]="Evento vazio";
if($data=="") $erros[]="Data vazia";
if(!count($_FILES[foto][name])) $erros[]="Selecione algum arquivo";
if(is_dir($evento)) $erros[]="Este evento j� existe.";


if(!count($erros)){
mkdir($evento);

      for($i=0;$i<count($_FILES[foto][name]);$i++){
      $type=$_FILES[foto][type][$i];
      $name=$_FILES[foto][name][$i];
      $temp_name=$_FILES[foto][tmp_name][$i];
      $file_erros=$_FILES[foto][error][$i];
      
      if($name!=""){
            if($type!="image/gif" &&  $type!="image/jpeg"){
            $erros[]="O arquivo $name, n�o � jpg, jpeg ou gif";
            }else{
                if($file_erros==1 || $file_erros==2)$erros[]="O arquivo $name � maior do que o limite definido.";
                if($file_erros==3) $erros[]="O arquivo $name est� corrompido.";
                if($file_erros==4) $erros[]="N�o foi feito a transfer�ncia do arquivo: $name";
                            if(!$file_erros){
                            move_uploaded_file($temp_name, $uploaddir."/$evento/".$name);
                            $validfiles[]=$name;
                            }
            }
      }
      
      }
      
if(count($validfiles)){
            $query1 = "INSERT INTO eventos (evento,data,ativo) VALUES ('$evento','$data','$ativo')";
            mysql_query($query1,$conexao);
            $ultimo = mysql_query("SELECT LAST_INSERT_ID() AS ULTIMO_ID", $conexao);
            $rs_ultimo = mysql_fetch_array($ultimo);
            $id_festa = $rs_ultimo['ULTIMO_ID'];

$data2 = date("Ymd");
$hora = date("H:i", time());
$ip = $_ENV['REMOTE_ADDR'];

            foreach($validfiles as $file){
            
            $query = "INSERT INTO fotos (id, id_festa, arquivo, descricao, ativo) VALUES (NULL,'$id_festa','$file','$descricao','$ativo')";
            mysql_query($query,$conexao);
            
            $log = "INSERT INTO log (inserido,data2,hora,ip) VALUES ('$inserido','$data2','$hora','$ip')";
            mysql_query($log,$conexao);
            }
            
            
}

echo "Arquivos enviados para o evento $evento em $data:<br/>";
   foreach($validfiles as $file){
   echo $file."<br/>";
   }
           if(count($erros)){
        echo "mas ocorreram alguns erros! verifique:<br/>";
        foreach($erros as $err){
        echo $err."<br/>";
        }

           }
}else{

        echo "Ocorreram alguns erros! verifique:<br/>";
        foreach($erros as $err){
        echo $err."<br/>";
        }


}

}
?></div>
</body>
</html>