function GestisciUpload($file_path = "models/")
{
$allowed_type = array
(
'application/acad',
'application/dxf',
'application/iges',
'application/sla',
'application/vnd.ms-pki.stl',
'application/x-navistyle',
'image/gif',
'image/jpeg',
'image/pjpeg',
'image/png',
'image/vnd.dwg',
'image/x-dwg',
'model/iges',
'x-world/x-3dmf',
);
$UploadErrors = array
(
'There is no error, the file uploaded with success',
'The uploaded file exceeds the upload_max_filesize directive in php.ini',
'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form',
'The uploaded file was only partially uploaded',
'No file was uploaded',
'Missing a temporary folder',
'Failed to write file to disk',
'A PHP extension stopped the file upload. PHP does not provide a way to ascertain which extension caused the file upload to stop; examining the list of loaded extensions with phpinfo() may help',
);
$err = $_FILES['fileToUpload']['error'];
if ($err > 0 )
{
echo "ERRORE : ".( $err < 8 ? $UploadErrors[$err] : $err )."<br /><br />";
return false;
}
if ( !is_dir($file_path) )
{
echo "ERRORE : La cartella di destinazione non esiste<br /><br />";
return false;
}
$file_name = $_FILES["fileToUpload"]["name"];
$file_type = strtolower($_FILES['fileToUpload']['type']);
$file_size = $_FILES['fileToUpload']['size'] / 1024;
$file_temp = $_FILES['fileToUpload']['tmp_name'];
$file = $file_path.$file_name;
echo "Upload : " .$file_name."<br />";
echo "Type : " .$file_type."<br />";
echo "Size (kB) : " .$file_size."<br />";
echo "Stored in : " .$file_temp."<br />";
echo "target folder : " .$file_path."<br />";
echo "target file : " .$file ."<br />";
if ( substr_count($file_name, ' ') )
{
echo "ERRORE : Il nome del file intercalato da spazi non è accettato. Rinomina il tuo file!<br /><br />";
return false;
}
if ( class_exists('finfo') )
{
$mime_type = ( new finfo(FILEINFO_MIME_TYPE) )->buffer( file_get_contents($file_temp) );
}
else if ( function_exists('mime_content_type') )
{
$mime_type = mime_content_type($file_temp);
}
else
{
echo "ERRORE : non posso ottenere 'mime_type' mancano gli strumenti php<br /><br />";
return false;
}
$mime_type = strtolower($mime_type);
echo "MIME TYPE : ".$mime_type."<br />";
if ( !in_array($mime_type, $allowed_type) )
{
echo "ERRORE : Il file non è del tipo corretto.<br /><br />";
return false;
}
if ($file_size == 0)
{
echo "ERRORE : Il file è vuoto.<br /><br />";
return false;
}
if ($file_size > 5000)
{
echo "ERRORE : Il file ha una dimensione troppo grande. Carica un file che non superi i 5 Mb.<br /><br />";
return false;
}
if ( file_exists($file) )
{
echo "ERRORE : Il nome scelto per il file esiste già. Rinomina il tuo file!<br /><br />";
return false;
}
if ( !move_uploaded_file($file_temp, $file) )
{
echo "ERRORE : Lo spostamento del file nella destinazione non è riuscito"."<br /><br />";
return false;
}
if (!file_exists($file))
{
echo "ERRORE : Il file non è arrivato a destinazione<br /><br />";
return false;
}
echo "Il file -- ".$file_name." -- è stato caricato correttamente.";
return true;
}