ActionScript - upload de archivos flash

 
Vista:

upload de archivos flash

Publicado por jesus aguilera (1 intervención) el 19/05/2013 11:33:05
Saludos, Necesito ayuda urgente he hecho un upload de archivos en flash, de hecho ya esta funcionando, me falta, además, del nombre y tamaño del archivo, añadir una descripción del mismo, y me estoy volviendo loco ya intentando cosas, mando el código flash y php para ver si me podéis ayudar, gracias de antemano.
------------- flash ---------
import flash.events.DataEvent;
import flash.net.FileReference;
var fileUpload:FileReference = new FileReference();
var path:String = "http://www.plusapl.net/uploadDir"
var escucha:Object = {};
var fileTypes:Array;
//var Desc:String = textdesc.text
var getFile:String; function init() {
System.security.allowDomain(path);
load_mc._visible = false;
fileTypes = [{description:"Archivos de Imagen", extension:"*.jpg;*.gif;*jpeg;*.png;*.pdf", macType:"JPEG;jp2_;GIFF"}];
upload_btn.label = "Upload File";
down_btn.label = "Download File";
upload_btn.addEventListener("click", doUpload);
down_btn.addEventListener("click", doDownload);
fileUpload.addListener(escucha);
escucha.onSelect = doSelect;
escucha.onComplete = doComplete;
escucha.onCancel = doCancel;
escucha.onProgress = doProgress;
data_mc.addEventListener("change", setDownload);
makeList();
}
function doComplete() {
load_mc.barra_mc._xscale = 0;
load_mc.label_txt.text = "Transfer Complete";
makeList();
}
function doProgress(archivo:FileReference, bLoaded:Number, bTotal:Number) {
var porcentaje = Math.round((bLoaded*100)/bTotal);
load_mc.label_txt.text = porcentaje+"% of File "+archivo.name;
load_mc.barra_mc._xscale = porcentaje;
}
function doCancel() {
trace("Cancel by user");
}
function doSelect(archivo:FileReference) {
load_mc._visible = true;
load_mc.barra_mc._xscale = 0;
fileUpload.upload(path+"/uploadFile.php");
}
function doDownload() {
if (getFile != undefined) {
fileUpload.download(path+"/"+getFile);
}
}
function doUpload(event) {
fileUpload.browse(fileTypes);
}
function setDownload(c:MovieClip) {
getFile = c.target.selectedItem.Name;
}
function makeList() {
data_mc.removeAll();
var list_xml:XML = new XML();
list_xml.ignoreWhite = true;
list_xml.load(path+"/lista.php");
list_xml.onLoad = function() {
var nodos = this.firstChild.childNodes;
for (var a in nodos) {
var size:Number = Math.ceil((nodos[a].attributes.tamanio/1024));
var Description:String = txtdesc.text((nodos[a].attributes.description));
data_mc.addItem({Name:nodos[a].attributes.name, Description:description, Size:size+" Kb"});
}
};
}
init();
--------PHP lista.
<?php
$No=array(".","..","lista.php","uploadFile.php");
$fp=opendir(".");
echo "<?xml version='1.0' ?".">";
echo "<files>";
while (false!==($file=readdir($fp))){
if ((!in_array($file,$No))&&(is_readable($file))){
echo "<file name='".utf8_encode($file)."' tamanio='".filesize($file)."' />";
}
}
closedir($fp);
echo "</files>";
?>
--------------------PHP uploadfile
<?php
$uploadDir = './';
$uploadFile = $uploadDir . $_FILES['Filedata']['name'];
move_uploaded_file($_FILES['Filedata']['tmp_name'], $uploadFile);
?>

Es muy simple, funciona todo muy bien, lo único añadir la descripción del archivo, gracias de antemano y en lo que yo pueda ayudar, cuenta con ello, mi correo, [email protected], gracias.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Alejandro

Agregar descripción al upload de archivos en Flash

Publicado por Alejandro (369 intervenciones) el 28/06/2023 17:30:55
1. En el código ActionScript, realiza los siguientes cambios:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import flash.events.DataEvent;
import flash.net.FileReference;
import flash.events.Event;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.net.URLVariables;
 
var fileUpload:FileReference = new FileReference();
var path:String = "http://www.plusapl.net/uploadDir";
var escucha:Object = {};
var fileTypes:Array;
var getFile:String;
var fileDescription:String; // Variable para almacenar la descripción del archivo
 
function init():void {
    System.security.allowDomain(path);
    load_mc.visible = false;
    fileTypes = [{description:"Archivos de Imagen", extension:"*.jpg;*.gif;*jpeg;*.png;*.pdf", macType:"JPEG;jp2_;GIFF"}];
    upload_btn.label = "Upload File";
    down_btn.label = "Download File";
    upload_btn.addEventListener(Event.CHANGE, doUpload);
    down_btn.addEventListener(MouseEvent.CLICK, doDownload);
    fileUpload.addListener(escucha);
    escucha.onSelect = doSelect;
    escucha.onComplete = doComplete;
    escucha.onCancel = doCancel;
    escucha.onProgress = doProgress;
    data_mc.addEventListener(Event.CHANGE, setDownload);
    makeList();
}
 
function doComplete():void {
    load_mc.barra_mc.scaleX = 0;
    load_mc.label_txt.text = "Transfer Complete";
    makeList();
}
 
function doProgress(archivo:FileReference, bLoaded:Number, bTotal:Number):void {
    var porcentaje:Number = Math.round((bLoaded * 100) / bTotal);
    load_mc.label_txt.text = porcentaje + "% of File " + archivo.name;
    load_mc.barra_mc.scaleX = porcentaje / 100;
}
 
function doCancel():void {
    trace("Cancel by user");
}
 
function doSelect(archivo:FileReference):void {
    load_mc.visible = true;
    load_mc.barra_mc.scaleX = 0;
    // Agregar la descripción del archivo a la solicitud del formulario
    var request:URLRequest = new URLRequest(path + "/uploadFile.php");
    var variables:URLVariables = new URLVariables();
    variables.description = fileDescription;
    request.method = URLRequestMethod.POST;
    request.data = variables;
    archivo.upload(request);
}
 
function doDownload():void {
    if (getFile != undefined) {
        fileUpload.download(new URLRequest(path + "/" + getFile));
    }
}
 
function doUpload(event:Event):void {
    fileUpload.browse(fileTypes);
}
 
function setDownload(c:MovieClip):void {
    getFile = c.target.selectedItem.Name;
}
 
function makeList():void {
    data_mc.removeAll();
    var listLoader:URLLoader = new URLLoader();
    listLoader.addEventListener(Event.COMPLETE, onListLoadComplete);
    listLoader.load(new URLRequest(path + "/lista.php"));
}
 
function onListLoadComplete(event:Event):void {
    var list_xml:XML = new XML(event.target.data);
    var nodos:XMLList = list_xml.children();
    for each (var nodo:XML in nodos) {
        var size:Number = Math.ceil((nodo.@tamanio / 1024));
        var description:String = String(nodo.@description); // Obtener la descripción del archivo
        data_mc.addItem({ Name:nodo.@name, Description:description, Size:size + " Kb" });
    }
}
 
init();

2. En el archivo "uploadFile.php", realiza los siguientes cambios:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
$uploadDir = './';
$
 
uploadFile = $uploadDir . $_FILES['Filedata']['name'];
 
// Obtener la descripción del archivo enviada desde Flash
$fileDescription = $_POST['description'];
 
move_uploaded_file($_FILES['Filedata']['tmp_name'], $uploadFile);
 
// Guardar la descripción en un archivo de texto con el mismo nombre del archivo subido
$descriptionFile = $uploadDir . pathinfo($uploadFile, PATHINFO_FILENAME) . ".txt";
file_put_contents($descriptionFile, $fileDescription);
?>

Con estos cambios, se ha agregado el soporte para la descripción del archivo en el upload de archivos en Flash. Al seleccionar un archivo para cargar, se enviará la descripción junto con el archivo al servidor PHP. Luego, en el servidor, se guardará la descripción en un archivo de texto con el mismo nombre del archivo subido.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar