Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

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:

    Flash:
    Code:
    function boothsEdit1BannerUploadClick(e:MouseEvent):void
    {    
        boothsEdit1File = new FileReference();
     
        var imgFileTypes:FileFilter = new FileFilter("Imgs (*.jpg, *.png)", "*.jpg;*.png;");
     
        boothsEdit1File.browse([imgFileTypes]);
        boothsEdit1File.addEventListener(Event.SELECT, boothsEdit1BannerUploadSelectFile);    
    }
    
    function boothsEdit1BannerUploadSelectFile(event:Event):void 
    {
        boothsEdit1DisableUI();
        boothsEdit1Status.text = "Banner uploading please wait...";
            
        var requestUpload:URLRequest = new URLRequest(boothsEdit1UploadScript);
        boothsEdit1File.upload(requestUpload);
        boothsEdit1File.addEventListener(Event.COMPLETE, boothsEdit1BannerFileLoaded);    
    }
    
    function boothsEdit1BannerFileLoaded(event:Event):void 
    {
        boothsEdit1EnableUI();
        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 "domain.com/files/filename" 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 156...it 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.

    Thanks
    Gemma

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

    Code:
    var variables:URLVariables = new URLVariables();
    vars.myVariableName = 'variableValue';
    var requestUpload:URLRequest = new URLRequest(boothsEdit1UploadScript);
    requestUpload.method = URLRequestMethod.POST;
    requestUpload.data = variables;
    boothsEdit1File.upload(requestUpload);
    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 kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012