Indice del forum Olimpo Informatico
I Forum di Zeus News
Leggi la newsletter gratuita - Attiva il Menu compatto
 
 FAQFAQ   CercaCerca   Lista utentiLista utenti   GruppiGruppi   RegistratiRegistrati 
 ProfiloProfilo   Messaggi privatiMessaggi privati   Log inLog in 

    Newsletter RSS Facebook Twitter Contatti Ricerca
script upload semplice
Nuovo argomento   Rispondi    Indice del forum -> Linguaggi per Internet
Precedente :: Successivo  
Autore Messaggio
mdweb
Dio maturo
Dio maturo


Registrato: 18/12/07 16:59
Messaggi: 4412

MessaggioInviato: 23 Feb 2008 15:17    Oggetto: script upload semplice Rispondi

Ciao a tutti vediamo ocme realizzare un semplice script PHP per l'unpload dei file:

Creaimo un file index.php che richiamerà i nostro file per l'upload
Codice:

<?php require_once("Upload.class.php"); ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   <title>Max's File Uploader</title>
   <link href="style/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php
    $myUpload = new Upload();
    //$myUpload->setUploadLocation(getcwd().DIRECTORY_SEPARATOR);
    $myUpload->uploadFile();
?>
</body>   


Ora ceriamo il file Upload.class.php che serve proprio per farsi inviare i file:

Codice:
<?php

class Upload{
    var $uploadLocation;
   
   
    function Upload(){
        $this->uploadLocation = getcwd().DIRECTORY_SEPARATOR;
    }

 
    function setUploadLocation($dir){
        $this->uploadLocation = $dir;
    }
   
    function showUploadForm($msg='',$error=''){
?>
       <div id="container">
            <div id="header"><div id="header_left"></div>
            <div id="header_main">Upload by md</div><div id="header_right"></div></div>
            <div id="content">
<?php
if ($msg != ''){
    echo '<p>'.$msg.'</p>';
} else if ($error != ''){
    echo '<p>'.$error.'</p>';

}
?>
                <form action="" method="post" enctype="multipart/form-data" >
                     <center>
                         <label>File:
                             <input name="myfile" type="file" size="30" />
                         </label>
                         <label>
                             <input type="submit" name="submitBtn" class="sbtn" value="Upload" />
                         </label>
                     </center>
                 </form>
             </div>
             <div id="footer"><a href="http://SONO UNO SPAMMER, IGNORA QUESTO MESSAGGIO! PRIMA O POI MI SBATTERANNO FUORI DAL FORUM PERCHE' SPAMMO.it" >Potenza da mdweb/a></div>
         </div>
<?php
    }

    function uploadFile(){
        if (!isset($_POST['submitBtn'])){
            $this->showUploadForm();
        } else {
            $msg = '';
            $error = '';
           
         
            if (!file_exists($this->uploadLocation)){
                $error = "The target directory doesn't exists!";
            } else if (!is_writeable($this->uploadLocation)) {
                $error = "The target directory is not writeable!";
            } else {
                $target_path = $this->uploadLocation . basename( $_FILES['myfile']['name']);

                if(@move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) {
                    $msg = basename( $_FILES['myfile']['name']).
                    " was uploaded successfully!";
                } else{
                    $error = "The upload process failed!";
                }
            }

            $this->showUploadForm($msg,$error);
        }

    }

}
?>


Buona fortuna!
Top
Profilo Invia messaggio privato
Mostra prima i messaggi di:   
Nuovo argomento   Rispondi    Indice del forum -> Linguaggi per Internet Tutti i fusi orari sono GMT + 2 ore
Pagina 1 di 1

 
Vai a:  
Non puoi inserire nuovi argomenti
Non puoi rispondere a nessun argomento
Non puoi modificare i tuoi messaggi
Non puoi cancellare i tuoi messaggi
Non puoi votare nei sondaggi