config.php
Codice PHP:
<?php
session_start();
$max_file = 10;
$num_inputFile = 1;
$max_size = 1024000.0;
$max_size_kb = $max_size/1024000;
$upload_dir = "prova";
$types = array( "application/zip", "application/rar" );
function prefix(){
$id_rand = rand(100, rand(150,300));
$id_rand = md5($id_rand );
return $id_rand;
}
?>
form.php
Codice PHP:
<?php
include("config.php");
if($_GET['n'] == "delete")
$_SESSION = array();
$_SESSION['maxfile'] = $num_inputFile;
if(isset($_GET['n']) && is_numeric($_GET['n']) && $_GET['n'] <= $max_file ){
$_SESSION['maxfile'] = $num_inputFile = $_GET['n'];
}
$_SESSION['md5'] = $md5 = md5(rand(1,50));
?>
<form action="send.php" method="post" enctype="multipart/form-data">
<table width="100%" align="left" >
<tr>
<td colspan="2"><div align="left"><strong>Add Model 3D</strong></td></div>
</tr>
<tr>
<td valign="top" width="16%"><strong>
<?php
echo "Numero di file da inviare: <br>";
for($i=1;$i<=$max_file;$i++)
echo " <a href=\"?n=$i\">$i</a><b>|</b>";
?>
</strong></td>
<td width="84%"><table><?php
for($i=0;$i<$num_inputFile;$i++){
echo "<tr><td><input type=\"file\" name=\"file_".$i."\"></td></tr>";
}
?></table></td>
</tr>
<tr>
<br><td style="color: rgb(255, 0, 0);"><? echo '<tr><td colspan="2">'.$final_report.'</td></tr>';?></td><br>
</tr>
<tr>
<td width="16%"><strong>Nome Modello:</strong></td>
<td width="84%"><input type="text" name="nome" value="<?php echo $_SESSION['nome']; ?>"></td>
</tr>
<tr>
<td><strong>Comment:</strong></td>
<td><input type="text" name="desc" value="<?php echo $_SESSION['desc']; ?>" ></td>
</tr>
<tr>
<td width="16%"><strong>Tipo Modello:</strong></td>
<td width="84%"><select name="tipo">
<option value="">Seleziona</option>
<option value="dirty">Dirty</option>
<option value="race">Race</option>
<option value="hobby">Hobby</option>
<option value="videogames">Videogames</option>
<option value="team">Team</option>
<option value="suv">Suv</option>
<option value="other">Other</option>
</select></td>
</tr>
<tr>
<td width="16%"><strong>Autore Modello:</strong></td>
<td width="84%"><input type="text" name="autore" value="<?php echo $_SESSION['autore']; ?>" ></td>
</tr>
<tr>
<td width="16%"><strong>Another Dettail:</strong></td>
<td width="84%"><textarea name="dettail" id="dettail" rows="5" cols="39"><?php echo $_SESSION['dettail']; ?></textarea></td>
</tr>
<td width="16%"><strong>ScreenShot Model:</strong></td>
<td width="84%"><input type="url" name="logo" value="<?php echo $_SESSION['logo']; ?>" ></td>
</tr>
<tr><td><input type="hidden" name="controlloMd5" value="<?php echo $md5; ?>">
<input type="submit" value="Invia file"><input type="button" onclick="window.location.href='?n=delete'" value="cancella" name="button">
</td></tr>
</div>
</table>
</form>
send.php
Codice PHP:
<?php
include("config.php");
//MODIFICARE IL NOME DEL FILE O INCLUDERE TUTTO DENTRO
//require('config.php');
$_SESSION['nome'] = $_POST['nome'];
$_SESSION['desc'] = $_POST['desc'];
$_SESSION['tipo'] = $_POST['tipo'];
$_SESSION['autore'] = $_POST['autore'];
$_SESSION['dettail'] = $_POST['dettail'];
$_SESSION['logo'] = $_POST['logo'];
$date = date("d-m-Y");
$set = "";
if($_POST['controlloMd5'] == $_SESSION['md5']){
$final_report = "";
if($_SESSION['nome'] == "" || $_SESSION['desc'] == "" ||
$_SESSION['tipo'] == "" || $_SESSION['autore'] == "" ||
$_SESSION['dettail'] == "" || $_SESSION['logo'] == ""){
$final_report.= "<b>ATTENZIONE: devi compilare tutti i campi:</b><br>";
}
if(strlen($_SESSION['nome']) <= 3 || strlen($_SESSION['nome']) >= 30){
$final_report.="Il nome del gruppo deve conprendere dai 3 i 30 caratteri!<br>";
}
if(strlen($_SESSION['desc']) <= 3 || strlen($_SESSION['desc']) >= 200){
$final_report.="Aggiungi una Descrizione per far trovare il tuo gruppo!<br>";
}
if(strlen($_SESSION['autore']) <= 3 || strlen($_SESSION['autore']) >= 30){
$final_report.="L'Autore del gruppo deve conprendere dai 3 i 30 caratteri!<br>";
}
if(strlen( $_SESSION['dettail']) <= 3 || strlen( $_SESSION['dettail']) >= 250){
$final_report.="Nel commento Max caratteri 250!<br>";
}
if($_SESSION['tipo'] == ""){
$final_report.="Non hai selezionato il tipo!<br>";
}
if($_SESSION['logo'] == ""){
$final_report.="Devi inserire il logo!<br>";
}
if($final_report != ""){
echo $final_report;
}
else{
for($i=0;$i<$_SESSION['maxfile'] ;$i++){
$upfile = "file_".$i;
$file_name = $_FILES[$upfile]['name'];
$file_tmp = $_FILES[$upfile]['tmp_name'];
$file_type = $_FILES[$upfile]['type'];
$file_size = $_FILES[$upfile]['size'];
if(trim($file_name) == "") {
echo "File".($i+1).": Non è stato indicato !<br>";
}
else if($file_size > $max_size){
echo "File".($i+1).": Supera la dimensione massima di ".($file_size-$max_size)." Byte !<br>";
}
else if(!in_array($file_type,$types)){
echo "File".($i+1).": (".$file_name.") estensione non consentita, sono ammesse solo le estensioni ".implode(",", $types)."<br>";
}
else{
if(is_uploaded_file($file_tmp)) {
$pref = prefix();
$set = "ok";
move_uploaded_file($file_tmp, "$upload_dir/$pref-$file_name") or die("Permessi della directory non settati, contattare l'amministratore del sito!.");
echo "File".($i+1).": " . $file_name . " inviato correttamente<br>";
}
else {
echo "Problemi nell'upload del file " . $file_name."<br>";
}
}}
if($set == "ok"){
// $addgroup ="INSERT INTO Model3d (id,nome,desc,tipo,autore,dettail,logo,date) VALUES ('','$nome','$desc', '$tipo','$autore','$dettail','$logo','$date')";
// if(!mysql_query($addgroup,$dbh)) /*eseguo la query e controllo se va a buon fine ^^*/
// die("<h1>".mysql_error()."</h1>");
// mysql_close($db_nome);
echo "query effettuata";
}
//primo if
}}
?>
<form>
<input type="button" value="Indietro" onclick="window.location.href='form.php'" name="button">
</form>