Codice PHP:
<?php
$nome         
$_SESSION['login'];
$uploadpath 'pages/gallery/';      // directory to store the uploaded files
$max_size     8000;          // maximum file size, in KiloBytes
$alwidth     1500;            // maximum allowed width, in pixels
$alheight     1500;           // maximum allowed height, in pixels
$allowtype     = array('bmp''gif''jpg''jpe''png');        // allowed extensions
$uploadpath $uploadpath."galleria_".$nome;       // gets the file name 
$err         ''

if (isset(
$_FILES['fileup']) && is_array($_FILES['fileup']))
{
    foreach (
$_FILES['fileup'] as $k => $_file)
    {
        
// Random name
        
$random md5(TIME_NOW $k);
    
        
// Check extension
        
$sepext explode('.'strtolower($_file[$k]['name']));
        
$type     end($sepext);       // gets extension 
        
if(!in_array($type$allowtype))
        {
            
$err .= 'Questo file: <b>'htmlspecialchars($_file[$k]['name']) . '</b> non ha un estensione conforme al sistema .';  
        }
        
        
// Check size
        
if ($_file[$k]['size'] > $max_size*8000)
        {
            
$err .= '<br/>''Questo file: <b>'htmlspecialchars($_file[$k]['name']) . '</b> &egrave; troppo pesante: '$max_size' KB.';  
        }
        
        
// Check width and height
        
list($width$height) = getimagesize($_file[$k]['tmp_name']);
        if(isset(
$width) && isset($height) && ($width >= $alwidth || $height >= $alheight)
        {
            
$err .= '<br/>''Questo file: <b>'htmlspecialchars($_file[$k]['name']) . '</b> supera le dimensioni di: '$alwidth' x '$alheight;
        }
        
        
// No errors?
        
if ($err == '')
        {
            if (
move_uploaded_file($_FILES['fileup']['tmp_name'], "$uploadpath/$random.$sepext")
            {
                echo 
'Upload  effetuato con successo per il file: '.htmlspecialchars($_file[$k]['name']);
            }
            else
            {
                
$err .= '<br/>''Errore sconosciuto, questo file non è stato caricato: <b>'htmlspecialchars($_file[$k]['name']) . ' riprova!';
            }
        }
        
        if (
$err != '')
        {
            echo 
$err;
        }
    }
}