The forums have permanently moved to This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Results 1 to 3 of 3

Thread: AS3 PHP File Upload

  1. #1

    AS3 PHP File Upload

    Hi there

    I have some fairly straightforward AS3 code that uploads a file to my server:

    function boothsEdit1BannerUploadClick(e:MouseEvent):void
        boothsEdit1File = new FileReference();
        var imgFileTypes:FileFilter = new FileFilter("Imgs (*.jpg, *.png)", "*.jpg;*.png;");
        boothsEdit1File.addEventListener(Event.SELECT, boothsEdit1BannerUploadSelectFile);    
    function boothsEdit1BannerUploadSelectFile(event:Event):void 
        boothsEdit1Status.text = "Banner uploading please wait...";
        var requestUpload:URLRequest = new URLRequest(boothsEdit1UploadScript);
        boothsEdit1File.addEventListener(Event.COMPLETE, boothsEdit1BannerFileLoaded);    
    function boothsEdit1BannerFileLoaded(event:Event):void 
        boothsEdit1Status.text = "Banner successfully uploaded";
    And the PHP upload script:
    PHP Code:
    if(!is_dir("./files")) mkdir("./files"0755); 
    move_uploaded_file($_FILES['Filedata']['tmp_name'], "./files"."/".$_FILES['Filedata']['name']);
    chmod("./files"."/".$_FILES['Filedata']['name'], 0777); 
    This all works great but my problem is, many users will be uploading their banners to this system and so I don't want them all in the same directory (/files) as the chances are they will be called banner.jpg etc.

    In the Flash code I am then saving the url of the uploaded banner as "" as this needs to be stored.

    So I would ideally like to use a unique ID for the directory. E.g. if I am using the system with my user ID of could upload my banner in to a folder called files156.

    The problem I have is, how can I pass that ID number to the PHP upload script? How can I add a variable called 'id' to my Flash code so that my PHP code can receive it using POST?

    Any ideas appreciated.


  2. #2
    You need to add a variable to your request:

    var variables:URLVariables = new URLVariables();
    vars.myVariableName = 'variableValue';
    var requestUpload:URLRequest = new URLRequest(boothsEdit1UploadScript);
    requestUpload.method = URLRequestMethod.POST; = variables;
    Then, in your PHP file:

    PHP Code:
    $variableValue $_POST['myVariableName']; 

  3. #3
    Works perfectly - thank you so much

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Home About Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012