Ver Mensaje Individual
  #8 (permalink)  
Antiguo 18/04/2007, 16:14
Avatar de cplus
cplus
 
Fecha de Ingreso: abril-2007
Mensajes: 164
Antigüedad: 17 años
Puntos: 1
Re: Comprobar extension del fichero para dar error

Código PHP:
/*
FileUpload.as
Sascha Wenning
Jan 2006

Feel free to customize for your needs
Code is partly documentated
*/

import mx.controls.gridclasses.DataGridColumn;
import flash.net.FileReference;
import flash.net.FileReferenceList;
import mx.containers.Window;
import mx.utils.Delegate;

class 
de.saschawenning.fileUpload.FileUpload{
    private var 
tl:MovieClip;
    private var 
titleWindow:String;
    private var 
frWindow:MovieClip//path to windowComponent
    
private var uploadMode;
    private var 
xCoord;
    private var 
yCoord;
    private var 
uploadDir;    
    private var 
pathUploadScript;
    private var 
pathXmlFileStructure;
    private var 
varss;
    
    private var 
waiter;
    private var 
xmlFileStructure;
    private var 
fileRef;
    private var 
fileRefListener;
    private var 
filesToUpload:Array;
    private var 
totalKilobytesToUpload;
    private var 
totalKiloBytesUploaded;
    private var 
filesUploaded//num of files uploaded
    
private static var maxFilesize//in MB per file you can set this also by hand to limit it
    
private var labelUploadBtn;
    

    public function 
FileUpload(timelinetitleWuploadModexCoordyCoorduploadDirpathUploadScriptpathXmlFileStructure){
        
//vars
        
this.tl timeline;
        
this.titleWindow titleW;
        
this.uploadMode uploadMode;
        
this.xCoord xCoord,
        
this.yCoord yCoord
        this
.uploadDir uploadDir;
        
this.pathUploadScript pathUploadScript;
        
this.pathXmlFileStructure pathXmlFileStructure
        
        
        totalKilobytesToUpload 
0;
        
totalKiloBytesUploaded 0;
        
filesUploaded 0;
        
filesToUpload = new Array();
        
labelUploadBtn "Enviar Ahora";
        
        
//init stuff
        
attachWindow();
    }
    
    
//xmlFileStructure fully loaded 
    
public function parseXmlFileStructure(success:Boolean){
        if(
success){
            if(
xmlFileStructure.status == 0){
                
//no error
            
} else {
                
frWindow.content.feedback_txt.htmlText "<p align='center'>An error occured while loading XmlFileStructure</p>";
            }
        } else {
            
frWindow.content.feedback_txt.htmlText "<p align='center'>Unable to load/parse XmlFileStructure. (Status: "+xmlFileStructure.status+")</p>"
        
}
        
frWindow.content.explorer_tree.dataProvider xmlFileStructure.firstChild;
    }
    
    
//user clicks select files button
    
public function browseClick(){
        
frWindow.content.feedback_txt.htmlText "";
        
checkLabelUploadBtn();
        
fileRef.browse();
    }
    
    
//user has selected some files
    
public function fileRefListener_onSelect(fileRefList:FileReferenceList){
        var list:Array = 
fileRefList.fileList;
        var 
tempList = new Array();

        for(var 
i=0i< list.lengthi++){
            var 
sizeFile = list[i].size/1024/1024//in MB
            
if((sizeFile maxFilesize) || (sizeFile >= 150)){ //150 MB is Flash Player limit per file
/**********************************************************************************************************/
                
frWindow.content.feedback_txt.htmlText "<p align='center'>Maximo 150 MB: El fichero excede del tamaño ("+Math.ceil(sizeFile)+" MB)";
/**********************************************************************************************************/
            
}else{

_root.mystring="hello people this ones useful"
if(_root.mystring.findstring(varss)){
    
trace("NO LO ENCONTRO !!!");
    
frWindow.content.feedback_txt.htmlText "<p align='center'>El tipo de fichero no esta permitido: Seleccione | *.rar | *.zip | *.ace | *.iso | *.bin | *.7z |";
}else{
    
tempList.push(list[i])
}

String.prototype.findstring=function(string){
    if(
this.indexOf(string) != -1){
        return 
true
    
}else{
        return 
false
    
}
}                    
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                

            }
            
        }
        
filesToUpload filesToUpload.concat(tempList);
        
frWindow.content.fileList_grid.dataProvider filesToUpload;
        
checkGridItems();
    }

    
    
//while upload is in progress disable user interface
    
public function disableWhileUploadContinues(){
        
frWindow.content.refreshTree_btn.enabled false;
        
frWindow.content.explorer_tree.enabled false;
        
frWindow.content.fileList_grid.enabled false;
        
frWindow.content.del_btn.enabled false;
        
frWindow.content.browse_btn.enabled false;
    }
    
    
//upload is completed: enable user interface
    
public function enableAfterUpload(){
        
frWindow.content.refreshTree_btn.enabled true;
        
frWindow.content.explorer_tree.enabled true;
        
frWindow.content.fileList_grid.enabled true;
        
frWindow.content.del_btn.enabled true;
        
frWindow.content.browse_btn.enabled true;
        
fileListChange();
        
checkGridItems();
        
updateTree();
    }    
    
    
//upload ach selected file
    
public function uploadFiles(){
        
filesUploaded 0;
        
totalKilobytesToUpload=0;
        
totalKiloBytesUploaded=0;
        
disableWhileUploadContinues();
        
        var 
item;
        for(var 
i:Number 0filesToUpload.lengthi++) {
            
item filesToUpload[i];
            
item.addListener(fileRefListener);
            
item.bereitsGeladen 0;
            if(!
item.upload(pathUploadScript+"?uploadDir="+uploadDir)) {
                
frWindow.content.feedback_txt.htmlText "Ocurrio un error en el dialogo Upload.";
            }
        }
    }
    
    
//if an upload process is completed and user wants
    //to upload more files
    
public function checkLabelUploadBtn(){
        if(
frWindow.content.upload_btn.label != labelUploadBtn){
            
frWindow.content.upload_btn.label labelUploadBtn;    
        }
    }
    
    
//check if grid is empty and enable/disable buttons
    
public function checkGridItems(){
        if(
frWindow.content.fileList_grid.dataProvider.length 0){
            if(
uploadMode == "Rich" && frWindow.content.explorer_tree.selectedItem.attributes.folders != undefined){
                
frWindow.content.upload_btn.enabled true;
                return 
true;
            }
            if(
uploadMode == "Simple"){
                
frWindow.content.upload_btn.enabled true;
            }
        }else{
            
frWindow.content.upload_btn.enabled false;
            
frWindow.content.del_btn.enabled false;
        }
    }
    
    
//cancel handler if you need it
    
public function fileRefListener_onCancel(){
        
trace("cancel");
    }
    
    
//determine uploaded filesize in percent regarding total filesize to upload
    
public function updateTransferStatus(){
        
totalKiloBytesUploaded 0;
        for(var 
i=0i<filesToUpload.lengthi++){
            
totalKiloBytesUploaded += filesToUpload[i].bereitsGeladen;
        }
        
frWindow.content.upload_btn.label "Enviando...   (" Math.round((totalKiloBytesUploaded/totalKilobytesToUpload)*100) + " %)";
    }
    
    
//if up- or download starts
    
public function fileRefListener_onOpen(file:FileReference){
         
totalKilobytesToUpload += (Math.ceil(file.size/1024));
         
updateTransferStatus();
         
    }    
    
    
//dispatch progress
    
public function fileRefListener_onProgress(filebytesLoaded:NumberbytesTotal:Number){
         
file.bereitsGeladen Math.ceil(bytesLoaded/1024);
         
updateTransferStatus();
    }
    
    
//when upload process is completed, clear grid
    
public function clearGrid(){
        
filesToUpload = new Array();
        
frWindow.content.fileList_grid.dataProvider filesToUpload;
        
checkGridItems();
    }
    
    
//a single file (perhaps in queue) has been uploaded
    
public function fileRefListener_onComplete(){
        
filesUploaded++;
        
updateTransferStatus();
        if(
filesUploaded == filesToUpload.length){
            
enableAfterUpload();
            
frWindow.content.upload_btn.label "Upload completado.";
            
clearGrid();
/**********************************************************************************************************/
            
getURL("index.php");
/**********************************************************************************************************/
        
}
    }