// Se il modulo viene inviato... if(isset($_POST['invia_pratica']) && $_FILES['userfile']['size'] > 0)
{
// Controllo id_prat
$query_id_prat = mysql_query("SELECT id_prat FROM pratiche WHERE id_prat = '" . mysql_insert_id() . "' ");
$dati_id_prat = mysql_fetch_array($query_id_prat);
$errors= array();
foreach($_FILES['userfile']['tmp_name'] as $key => $tmp_name ){
$fileName = $key.$_FILES['userfile']['name'][$key];
$fileSize =$_FILES['userfile']['size'][$key];
$tmpName =$_FILES['userfile']['tmp_name'][$key];
$file_type=$_FILES['userfile']['type'][$key];
$id_pratica = $dati_id_prat[id_prat];
if(!get_magic_quotes_gpc()){
$fileName = addslashes($fileName);
$fileSize = addslashes($fileSize);
$file_type = addslashes($file_type);}
if($fileSize > 2097152){
$errors[]='File size must be less than 2 MB';
}
// Controllo id utente
$query_ut_utenti = mysql_query("SELECT * FROM utenti WHERE id = '" . $_SESSION['login'] . "' LIMIT 1");
$dati_ut_utenti = mysql_fetch_array($query_ut_utenti);
$id_ut_utenti = $dati_id['id'];
// Controllo nome utente
$nome = $dati_id['nome'] ." ";
$cognome = $dati_id['cognome'];
$nome_utente = $nome .$cognome;
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
$query = "INSERT INTO upload (id_pratica, id_ut_utenti, name, size, type, content ) "." VALUES ('$id_pratica', '$id_ut_utenti', '$fileName', '$fileSize', '$fileType', '$content')";
$desired_dir= $_SERVER["DOCUMENT_ROOT"] = "/membri/qui_ho_messo_il_mio_dominio/uplds/";
if(empty($errors)==true){
if(is_dir($desired_dir)==false){
mkdir("$desired_dir", 0700); // Create directory if it does not exist
}
if(is_dir("$desired_dir/".$fileName)==false){
move_uploaded_file($tmpName,"$desired_dir/".$fileName);
}else{ // rename the file if another one exist
$new_dir="$desired_dir/".$fileName.time();
rename($tmpName,$new_dir) ;
}
mysql_query($query);
}else{
print_r($errors);
}
}
if(empty($error)){
echo "Success";
}
// Reindirizzo l'utente ad una pagina di conferma della registrazione
header('Location: gest_ptc.php');
exit;
}