WebSite-PHP Framework PHP
Multi language
Simple Ajax mode
No HTML, no JavaScript
URL rewriting
Mail sending
Sitemap - RSS - Web service
Download WebSite-PHP FrameWork now
 


Loading
 


Tutorial : Upload multiple files 
with ajax event

Tutorials

>

Tutorial Uploadfile

>

Tutorial : Upload multiple files with ajax event


Uploadfile-03: Tutorial of the composant Uploadfile of the PHP FrameWork WebSite-PHP.

Tutorial : Upload multiple files with ajax event:



Go back to tutorial of the componant Uploadfile



Source code

Source code


File: /pages/tutorials/uploadfile/uploadfile-03.php

<?php
class Uploadfile03 extends Page {
    public function 
InitializeComponent() {
        
parent::$PAGE_TITLE "Tutorial : Upload multiple files 
                    with ajax event"
;
        
        
// create upload files
        
$this->uploads = new UploadFile($this);
        
$this->uploads->activateMultipleFiles();
        
        
// define mime type authorized 
        
$this->uploads->setAuthorizedMimeTypes(array(
                
"image/jpeg","image/png""image/gif"));
        
        
// define file size limit
        
$this->uploads->setFileSizeLimit("300kb");
        
        
// define the event method
        
$this->uploads->setAjaxEvent();
        
$this->uploads->onChange("onUploads");
        
        
$this->render $this->uploads;
    }
    
    public function 
onUploads($sender) {
        
// check the files are correctly uploaded
        
for ($i $i $this->uploads->count(); $i++) {
            if (
$this->uploads->checkMimeType($i) && 
                
$this->uploads->checkFileSize($i)) {
                    
alert("File ".$this->uploads->getFileName($i)." (".
                        
$this->uploads->getFileSize($i).") uploaded !");
            } else if (
$this->uploads->isEmptyFile($i)) {
                
alert("Your file ".$this->uploads->getFileName($i)." is empty !");
            } else if (!
$this->uploads->checkFileSize($i)) {
                
alert("Your file ".$this->uploads->getFileName($i)." is too big !");
            } else {
                
alert("Mime type ".$this->uploads->getFileMimeType($i).
                        
" of the file ".$this->uploads->getFileName($i).
                        
" is not supported !");
            }
        }
    }
}
?>


Go back to tutorial of the componant Uploadfile


Share

 


Copyright © 2009-2024 WebSite-PHP Framework PHP
Home Documentation Download Quick start Tutorials Wiki Issue Tracker