<?php
$target_dir = "models/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($_FILES["fileToUpload"]["name"],PATHINFO_EXTENSION));//in modo che sia sempre tutto minuscolo
var_dump($imageFileType);
// Check if image file is a actual image or fake
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "Rapporto di invio:<br><br>Il file è del tipo corretto -- TIPO -- " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "Rapporto di invio:<br><br><ERRORE:<br>Il file non è del tipo corretto.<br><br>";
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
echo "<br><br>ERRORE:<br>Il nome scelto per il file esiste già. Rinomina il tuo file!<br>";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 5000000) {
echo "<br>Il tuo file ha una dimensione troppo grande. Carica un file che non superi i 5Mb<br>";
$uploadOk = 0;
}
$tipo=array('jpg','jpeg','gif','png','dwg','dxf','igs','stl','3dm','3dmf');//aggiungi e/o togli le estenzioni che ti interessano
//verifico che l'estensione sia tra i tipi ammessi
if(!in_array($imageFileType,$tipo)){//l'estensione non è nell'arrai
echo "<br>Solo i files di tipo JPG, JPEG, GIF, PNG, DWG, DXF, IGS, STL, 3DM, 3DMF, possono essere caricati.<br>";//se vuoi elencarli oppure
//echo "<br>non è ammesso caricare file tipo $imageFileType.<br>";
$uploadOk = 0;//file NON consentito
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "<br>Spiacente, il tuo file non è stato caricato!<br> Verifica e correggi gli errori elencati e riprova.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "<br><br><br>Il file -- ". basename( $_FILES["fileToUpload"]["name"]). " -- è stato caricato correttamente.";
} else {
echo "<br>Spiacente, si è verificato un'errore durante l'invio del tuo file.";
}
}
?>