Upload Component, Pass extra Variable


hello all.

 

i have been trying upload component work time now, have been having few troubles getting 1 need.  found component pretty want bar 1 thing, pass variable php script can name files unique.

 

my flex code -

<?xml version="1.0" encoding="utf-8"?>
<s:application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx"
               creationcomplete="init()" width="600" height="300">
    <fx:script>
        <![cdata[
           
            private var urlrequest:urlrequest;
            private var filereferencelist:filereferencelist;
            private var serversidescript:string = "http://www.davidtest.webcastglobal.com/upload/upload.php";
            [bindable] public var id:string;
           
            private function init():void {
                urlrequest = new urlrequest(serversidescript);
                filereferencelist = new filereferencelist();
                filereferencelist.addeventlistener(event.select, fileselectedhandler);
            }
           
            private function uploadfile():void {
                filereferencelist.browse();
            }
           
            private function fileselectedhandler(event:event):void {
                var filereference:filereference;
                var filereferencelist:filereferencelist = filereferencelist(event.target);
                var filelist:array = filereferencelist.filelist;
               
                // first file user chose
                filereference = filereference(filelist[0]);
               
                // upload file server side script
                filereference.addeventlistener(event.complete, uploadcompletehandler);
                filereference.upload(urlrequest);
               
                // update status text
                statustext.text = "uploading...";
            }
           
            private function uploadcompletehandler(event:event):void {
                statustext.text = "file uploaded: " + event.target.name;
            }
           
        ]]>
    </fx:script>
   
    <s:bordercontainer width="300" height="96" horizontalcenter="0" verticalcenter="0">
        <mx:label text="upload cv" fontweight="bold" horizontalcenter="0" top="10"/>
        <mx:label text="choose file..." id="statustext" horizontalcenter="0" top="35"/>
        <mx:button click="uploadfile();" label="upload file" horizontalcenter="0" bottom="10"/>
    </s:bordercontainer>
   
</s:application>

 

while php code it

<?php

$tempfile = $_files['filedata']['tmp_name'];
$filename = $_files['filedata']['name'];
$filesize = $_files['filedata']['size'];
$id = $_post["id"]

$newname = '$id'.'.doc';
move_uploaded_file($tempfile, "./" . $newname);

?>

 

what trying is, when user clicks "upload file" button on flex app, after pick file, uploads file using name of given file.  want do, pass variable "id" php , use file name instead.

 

im little bit stumped how ?  dont know include code pass "id",  deal httpsservice's declare such things in function.


any great.!

you should able add parameter using urlvariables, change init function like:

 

            private function init():void {
                urlrequest = new urlrequest(serversidescript);
                var variables:urlvariables = new urlvariables();
                variables.myfilename = "flexponential";
                urlrequest.data = variables;
                filereferencelist = new filereferencelist();
                filereferencelist.addeventlistener(event.select, fileselectedhandler);
            }

 

and in php file should able access data via post variable.

 

$myfilename = $_post["myfilename"];

 



More discussions in Flex (Read Only)


adobe

Comments

Popular posts from this blog

How to decompile jsxbin to jsx

Gavik Photoslide GK2: Not able to upload photos - Joomla! Forum - community, help and support

Phoca Guestbook logger registret bruger af - Joomla! Forum - community, help and support