Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form action="pagina.php" method="post" enctype="multipart/form-data">
- <span style="color: #DA3A11;">Estensioni permesse:</span> JPG, JPEG, GIF, PNG, PSD, TXT, PDF, DOC, DOCX, MP3, MP4, AVI, ZIP, RAR<br><br>
- <label for="file">Scegli il file: </label>
- <input type="file" name="file" id="file">
- <br>
- <br>
- <input type="submit" name="send" value="Invia File">
- <br>
- <br>
- <span style="color: #DA3A11;">Dimensione massima del file:</span> 3 KB
- <br>
- <br>
- </form>
- <!-- FINE UPLOAD FILE -->
- <?php
- if(isSet($_POST['send'])) { // Se richiedo l'upload del file
- // Estensioni permesse
- $allowedExts = array("gif", "jpeg", "jpg", "png", "txt", "pdf", "doc", "docx", "mp3", "avi", "mp4", "psd", "zip", "rar"); // Array di estensioni permesse
- $extension = end(explode(".", $_FILES['file']['name'])); // Prendo l'estensione del file caricato
- $max_fsize = 3500; // Limite massimo grandezza file impostata a 3 KB per le prove
- $errore = ""; // Imposto errore
- if($_FILES['file']['size'] > $max_fsize) {
- // Se il file รจ troppo grande
- $errore .= "<span style='color: #DA3A11;'>La dimensione del file deve essere inferiore a 3 KB</span><br>";
- }
- if(!in_array(strtolower($extension), $allowedExts)) {
- // Se il file e' di una estensione non permessa
- $errore = "<span style='color: #DA3A11;'>L'estensione del file (".$extension.") non e' consentita</span><br>";
- if($extension == "php" || $extension == "asp" || $extension == "html" || $extension == "js" || $extension == "htaccess") $errore .= "<span style='color: #33CCFF;'>Estensione non permessa per la sicurezza del sito!</span><br>";
- }
- if($errore) {
- // Se ho un errore specifico
- echo "<span style='color: #FFFFFF;'>Errore:</span> " . $errore . "<br><br>";
- }
- else {
- // Se non ci sono errori specifici
- // Cerco errori generici di altro tipo
- if($_FILES['file']['error'] > 0) {
- echo "<span style='color: #FFFFFF;'>Codice errore:</span><span style='color: #DA3A11;'> " . $_FILES['file']['error'] . "</span><br>";
- }
- else {
- // Se non ci sono nemmeno errori generici di altro tipo
- // Inizio il caricamento del file
- echo "<span style='color: #DA3A11;'>Caricamento del file:</span> " . $_FILES['file']['name'] . "<br>";
- echo "<span style='color: #DA3A11;'>Tipo di file:</span> " . $_FILES['file']['type'] . "<br>";
- echo "<span style='color: #DA3A11;'>Estensione:</span> " . $extension . "<br>";
- echo "<span style='color: #DA3A11;'>Grandezza file:</span> " . floor($_FILES['file']['size'] / 1024) . " kB<br><br>";
- $numero = rand(10000, 9999999); // Numero da 10.000 a 9.999.999
- $nome_assegnato = $numero . "." . $extension; // Imposto un nome da assegnare al file
- while(file_exists("" . $nome_assegnato)) {
- // Se il file che sto salvando esiste gia'
- // Genero un altro numero e provo con quello
- $numero = rand(10000, 99999); // Numero da 10.000 a 99.999
- $nome_assegnato = $numero . "." . $extension;
- }
- move_uploaded_file($_FILES['file']['tmp_name'], "art_files/articolo_10_upload_file/" . $nome_assegnato);
- echo "<span style='color: #DA3A11; font-size: 16px;'>File salvato:</span> <a target='_blank' href='http://chrmar.altervista.org/articoli/art_files/articolo_10_upload_file/" . $nome_assegnato . "'>". $nome_assegnato . "</a><br><br>";
- }
- }
- } // Fine isSet
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement