WebSite-PHP Framework PHP
Multi langues
Mode Ajax simple
Aucun HTML, aucun JavaScript
URL rewrinting
Envoi d'email
Sitemap - RSS - Web service
Télécharger le Framework WebSite-PHP maintenant
 


Loading
 


Tutorial : Upload a file 
by choosing from an icon the file (with ajax event)

Tutoriels

>

Tutoriel Uploadfile

>

Tutorial : Upload a file by choosing from an icon the file (with ajax event)


Uploadfile-06: Tutoriel du composants Uploadfile du FrameWork PHP WebSite-PHP.

Tutorial : Upload a file by choosing from an icon the file (with ajax event):



Retourner aux tutoriels du composants Uploadfile



Code source

Code source


Fichier: /pages/tutorials/uploadfile/uploadfile-06.php

<?php
class Uploadfile06 extends Page {
    public function 
InitializeComponent() {
        
parent::$PAGE_TITLE "Tutorial : Upload a file 
                    by choosing from an icon the file (with ajax event)"
;
        
        
// create upload file
        
$this->upload = new UploadFile($this);

        
// Define the icon to select the file (replace the normal input)
        
$this->upload->setSelectFileIcon("img/paper_clip_32.png");
        
        
// define mime type authorized 
        
$this->upload->setAuthorizedMimeTypes(array(
                
"image/jpeg","image/png""image/gif"));
        
        
// define file size limit
        
$this->upload->setFileSizeLimit("300kb");
        
        
// define the event method
        
$this->upload->setAjaxEvent();
        
$this->upload->onChange("onUpload");
        
        
$this->render $this->upload;
    }
    
    public function 
onUpload($sender) {
        
// check the file is correctly uploaded
        
if ($this->upload->checkMimeType() && 
            
$this->upload->checkFileSize()) {
                
alert("File ".$this->upload->getFileName()." (".
                    
$this->upload->getFileSize().") uploaded !");
        } else if (
$this->upload->isEmptyFile()) {
            
alert("Your file is empty !");
        } else if (!
$this->upload->checkFileSize()) {
            
alert("Your file is too big !");
        } else {
            
alert("Mime type ".$this->upload->getFileMimeType().
                    
" not supported !");
        }
    }
}
?>


Retourner aux tutoriels du composants Uploadfile


Share

 


Copyright © 2009-2024 WebSite-PHP Framework PHP
Accueil Documentation Télécharger Quick start Tutoriels Wiki Issue Tracker