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

Código PHP:
    //user clicks tree
    //set new uploadDir
    
public function explorer_treeChange(whoSaid){
        
checkLabelUploadBtn();
        
        var 
theTree whoSaid.target;
        
//we can't use getIsBranch() because folder could be empty
        
var isBranch:Boolean theTree.selectedItem.attributes.folders != undefined;
        
frWindow.content.feedback_txt.htmlText "";
        var 
node theTree.selectedItem;
        if(
isBranch && checkGridItems()){
            
uploadDir node.attributes.fullpath "/";
            
frWindow.content.upload_btn.enabled true;
        }else if(
isBranch){
                
uploadDir node.attributes.fullpath "/";
        }else{
            
frWindow.content.upload_btn.enabled false;
            if(!
isBranch){
                
frWindow.content.feedback_txt.htmlText "<p align='center'>Info: Please select a destination FOLDER, not a file.</p>";
            }
        }
    }
    
    
//get actual tree source
    
public function updateTree(){
        if(
uploadMode == "Rich"){
            
xmlFileStructure.load(pathXmlFileStructure);
        }
    }
    
    
//files grid change event
    
public function fileListChange(){
        
checkLabelUploadBtn();
        
        if(
frWindow.content.fileList_grid.selectedItem != undefined){
            
frWindow.content.del_btn.enabled true;
        }else{
            
frWindow.content.del_btn.enabled false;
        }
    }
    
    
//delete file from dataProvider
    
public function delFileFromList(){
        
checkLabelUploadBtn();
        
        var 
numItems:Number frWindow.content.fileList_grid.length;
        for(var 
i=0i<numItemsi++){
            var 
numSelectedIndices frWindow.content.fileList_grid.getSelectedIndices();
            
frWindow.content.fileList_grid.removeItemAt(numSelectedIndices[numSelectedIndices.length-1])
        }
        
        
filesToUpload frWindow.content.fileList_grid.dataProvider;
        
fileListChange();
        
checkGridItems();
    }
    
    
//some lyout operations
    
public function setupFilesGrid(){
        var 
theGrid frWindow.content.fileList_grid;

        var 
column = new DataGridColumn("name");
        
column.headerText "                                                                                         Nombre Fichero";
        
column.width 600;
        
theGrid.addColumn(column);        

/********************************************************************************************/
        
varss frWindow.content.fileList_grid;
        
trace(varss);
/********************************************************************************************/
        
        
var column = new DataGridColumn("size");
        
column.headerText "     Tamaño";
        
column.width 100;
        
column.labelFunction = function(item):String {
            if ((
item.size != undefined) && (item.name != undefined)) {
                return ((
Math.ceil(item.size/1024)) + " KB");
            }
        }

        
theGrid.addColumn(column);            
    }
    
    
//layout simple mode
    
public function layoutForSimple(){
        
frWindow.content.refreshTree_btn._visible false;
        
frWindow.content.explorer_tree._visible false;
/********************************************************************************************/
        
frWindow.setSize(720300);    
/********************************************************************************************/        
        
setupFilesGrid();
        
        
frWindow.content.fileList_grid.move(10,10);
        
frWindow.content.fileList_grid.setSize(700,160);
        
        
frWindow.content.labelFilesToUpload_mc._visible false;
        
frWindow.content.labelUploadDestination_mc._visible false;
        
        
frWindow.content.browse_btn.move(frWindow.content.fileList_grid._x frWindow.content.fileList_grid.width frWindow.content.browse_btn.width,180);
        
frWindow.content.del_btn.move(frWindow.content.browse_btn._x-frWindow.content.del_btn.width-10,180);
        
frWindow.content.del_btn.enabled false;
        
frWindow.content.upload_btn.setSize(frWindow.content.fileList_grid.width,35);
        
frWindow.content.upload_btn.move(frWindow.content.fileList_grid._xfrWindow.content.del_btn._y frWindow.content.del_btn._height 10);
        
frWindow.content.upload_btn.enabled false;
        
frWindow.content.feedback_txt._width frWindow.content.upload_btn.width;
        
frWindow.content.feedback_txt._x frWindow.content.upload_btn.x;
        
frWindow.content.feedback_txt._y frWindow.content.upload_btn.frWindow.content.upload_btn.height 1;        
    }
    
    
//layout rich mode
    
public function layoutForRich(){
        
frWindow.setSize(610400);    
        
        
setupFilesGrid();
        
        
frWindow.content.fileList_grid.move(frWindow.content.explorer_tree._x frWindow.content.explorer_tree.width10frWindow.content.explorer_tree._y 22);
        
frWindow.content.fileList_grid.setSize(375,200);
        
        
frWindow.content.labelFilesToUpload_mc._x frWindow.content.fileList_grid.x;
        
frWindow.content.labelFilesToUpload_mc._y frWindow.content.fileList_grid.22;
        
frWindow.content.labelUploadDestination_mc._x frWindow.content.explorer_tree.x;
        
frWindow.content.labelUploadDestination_mc._y frWindow.content.explorer_tree.22;
        
        
frWindow.content.browse_btn.move(frWindow.content.fileList_grid._x frWindow.content.fileList_grid.width frWindow.content.browse_btn.widthfrWindow.content.fileList_grid._y frWindow.content.fileList_grid.height 10);
        
frWindow.content.del_btn.move(frWindow.content.browse_btn._x-frWindow.content.del_btn.width-10frWindow.content.browse_btn._y);
        
frWindow.content.del_btn.enabled false;
        
frWindow.content.upload_btn.setSize(frWindow.content.fileList_grid.width,35);
        
frWindow.content.upload_btn.move(frWindow.content.fileList_grid._xfrWindow.content.del_btn._y frWindow.content.del_btn._height 10);
        
frWindow.content.upload_btn.enabled false;
        
frWindow.content.feedback_txt._width frWindow.content.upload_btn.width;
        
frWindow.content.feedback_txt._x frWindow.content.upload_btn.x;
        
frWindow.content.feedback_txt._y frWindow.content.upload_btn.frWindow.content.upload_btn.height 5;
    }    
    
    
//ask web server phpinfo() to return possible maxUpload filesize
    
public function getPhpUploadSettings(){
        var 
phpRestrictions = new LoadVars();
        
phpRestrictions.action "getMaxFilesize";
        
phpRestrictions.sendAndLoad(pathUploadScriptphpRestrictions"POST");
        
phpRestrictions.refThis this;
        
phpRestrictions.onLoad = function(success){
            if(
success){
                
maxFilesize phpRestrictions.maxFilesize.substr(0,phpRestrictions.maxFilesize.length-2);
                if(
maxFilesize.length 5){
                    
//path to ini_get is relative and environment is desptop
                    //so php can not be interpreted
                    
this.refThis.frWindow.content.feedback_txt.htmlText "<p align='center'>An Error occured (can't get maxFilesize)</p>";
                }
            }else{
                
this.refThis.frWindow.content.feedback_txt.htmlText "<p align='center'>An Error occured (can't get maxFilesize)</p>";
            }
        }    
    }
    
    
//-------------------------------------------------------------------------------------
    //window component is attached and contentPath has initialized...
    //...so fire the laser
    //-------------------------------------------------------------------------------------
    
public function initFileBrowser(){
        
frWindow.content.feedback_txt.htmlText "";
        
frWindow.content.upload_btn.label labelUploadBtn;
        
        if(
uploadMode == "Rich"){
            
layoutForRich();
        }
        
        if(
uploadMode == "Simple"){
            
layoutForSimple();
        }
        
        
getPhpUploadSettings();
        
        
//get file structure data for explorer_tree
        //is invoked in all modes, you could change this...
        
xmlFileStructure = new XML();
        
xmlFileStructure.ignoreWhite true;
        
xmlFileStructure.onLoad Delegate.create(thisparseXmlFileStructure);
        
updateTree();
        
        
//create reference object
        
fileRef = new FileReferenceList();
        
fileRefListener = new Object();
        
fileRefListener.onSelect Delegate.create(thisfileRefListener_onSelect);
        
fileRefListener.onCancel Delegate.create(thisfileRefListener_onCancel);
        
        
fileRefListener.onOpen Delegate.create(thisfileRefListener_onOpen);
        
fileRefListener.onProgress Delegate.create(thisfileRefListener_onProgress);
        
fileRefListener.onComplete Delegate.create(thisfileRefListener_onComplete);
        
fileRef.addListener(fileRefListener);
        
        
//events
        
frWindow.content.browse_btn.addEventListener("click"Delegate.create(thisbrowseClick));
        
frWindow.content.upload_btn.addEventListener("click"Delegate.create(thisuploadFiles));
        
frWindow.content.refreshTree_btn.addEventListener("click"Delegate.create(thisupdateTree));
        
frWindow.content.fileList_grid.addEventListener("change"Delegate.create(thisfileListChange));
        
frWindow.content.del_btn.addEventListener("click"Delegate.create(thisdelFileFromList));
        
        
frWindow.content.explorer_tree.setStyle("openDuration"0);
        
frWindow.content.explorer_tree.addEventListener("change"Delegate.create(thisexplorer_treeChange));
    }
    
    public function 
waitForAttachedContent(arguments){
        if(
frWindow.content != undefined){
            
initFileBrowser();
            
clearInterval(waiter);
        }
    }
    
    public function 
attachWindow(){
        
frWindow mx.managers.PopUpManager.createPopUp(tlWindowtrue, {closeButton:truetitle:titleWindowcontentPath:"fileUpload_mc"});
        
frWindow.move(xCoordyCoord);
        
        var 
frWindowListener:Object = new Object();
        
frWindowListener.click = function(whoSaid:Object) {
            
whoSaid.target.deletePopUp();
            };
        
        
frWindow.addEventListener("click"frWindowListener);

        
waiter setInterval(Delegate.create(thiswaitForAttachedContent), 250);
    }