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=0; i<numItems; i++){
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(720, 300);
/********************************************************************************************/
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._x, frWindow.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.y + frWindow.content.upload_btn.height + 1;
}
//layout rich mode
public function layoutForRich(){
frWindow.setSize(610, 400);
setupFilesGrid();
frWindow.content.fileList_grid.move(frWindow.content.explorer_tree._x + frWindow.content.explorer_tree.width+ 10, frWindow.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.y - 22;
frWindow.content.labelUploadDestination_mc._x = frWindow.content.explorer_tree.x;
frWindow.content.labelUploadDestination_mc._y = frWindow.content.explorer_tree.y - 22;
frWindow.content.browse_btn.move(frWindow.content.fileList_grid._x + frWindow.content.fileList_grid.width - frWindow.content.browse_btn.width, frWindow.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-10, frWindow.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._x, frWindow.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.y + 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(pathUploadScript, phpRestrictions, "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(this, parseXmlFileStructure);
updateTree();
//create reference object
fileRef = new FileReferenceList();
fileRefListener = new Object();
fileRefListener.onSelect = Delegate.create(this, fileRefListener_onSelect);
fileRefListener.onCancel = Delegate.create(this, fileRefListener_onCancel);
fileRefListener.onOpen = Delegate.create(this, fileRefListener_onOpen);
fileRefListener.onProgress = Delegate.create(this, fileRefListener_onProgress);
fileRefListener.onComplete = Delegate.create(this, fileRefListener_onComplete);
fileRef.addListener(fileRefListener);
//events
frWindow.content.browse_btn.addEventListener("click", Delegate.create(this, browseClick));
frWindow.content.upload_btn.addEventListener("click", Delegate.create(this, uploadFiles));
frWindow.content.refreshTree_btn.addEventListener("click", Delegate.create(this, updateTree));
frWindow.content.fileList_grid.addEventListener("change", Delegate.create(this, fileListChange));
frWindow.content.del_btn.addEventListener("click", Delegate.create(this, delFileFromList));
frWindow.content.explorer_tree.setStyle("openDuration", 0);
frWindow.content.explorer_tree.addEventListener("change", Delegate.create(this, explorer_treeChange));
}
public function waitForAttachedContent(arguments){
if(frWindow.content != undefined){
initFileBrowser();
clearInterval(waiter);
}
}
public function attachWindow(){
frWindow = mx.managers.PopUpManager.createPopUp(tl, Window, true, {closeButton:true, title:titleWindow, contentPath:"fileUpload_mc"});
frWindow.move(xCoord, yCoord);
var frWindowListener:Object = new Object();
frWindowListener.click = function(whoSaid:Object) {
whoSaid.target.deletePopUp();
};
frWindow.addEventListener("click", frWindowListener);
waiter = setInterval(Delegate.create(this, waitForAttachedContent), 250);
}
}