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

Tutoriels

>

Tutoriel Uploadfile

>

Tutorial : Upload a file


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

Tutorial : Upload a file:




Retourner aux tutoriels du composants Uploadfile



Code source

Code source


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

<?php
class Uploadfile01 extends Page {
    public function 
InitializeComponent() {
        
parent::$PAGE_TITLE "Tutorial : Upload a file";
        
        
$form = new Form($this);
        
        
$form_obj = new Object();
        
$form_obj->setAlign(Object::ALIGN_CENTER);
        
        
// it's not possible in a Tabs or DialogBox to use
        // button to upload a file.
        // To check if we are in the case of Tab we init
        // variable used bellow in the code
        
$isTabs $this->isAjaxLoadPage() || 
                    
$this->isAjaxPage();
        
        
// create upload file
        
$this->upload = new UploadFile(
                            (
$isTabs?$this:$form));
        
        
// define mime type authorized 
        
$this->upload->setAuthorizedMimeTypes(array(
                
"image/jpeg","image/png""image/gif"));
        
        
// define file size limit
        
$this->upload->setFileSizeLimit("300kb");
        
        
$form_obj->add($this->upload);
        
        if (!
$isTabs) {
            
// We will display the button only in a classic page
            
$btn = new Button($form);
            
$btn->setValue("Upload")->onClick("onClick");
            
$form_obj->add("<br/>"$btn);
            
            
$form->setContent($form_obj);
            
$this->render $form;
        } else {
            
// We are in the Tabs and we need to set ajax
            // event to upload a file
            
$this->upload->setAjaxEvent();
            
$this->upload->onChange("onClick");
            
            
// Display message to explain
            
$link = new Link("tutorials/uploadfile/uploadfile-01.html"
                            
Link::TARGET_NONE
                            
"tutorials/uploadfile/uploadfile-01.html");
            
$form_obj->add("<br/><br/>To use UploadFile in a Tab, it's ".
                
"necessary to use ajax event.<br/>Please go on the page "
                
$link" to test without ajax event.");
            
            
$this->render $form_obj;
        }
    }
    
    public function 
onClick($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-2016 WebSite-PHP Framework PHP
Accueil Documentation Télécharger Quick start Tutoriels Wiki Issue Tracker