# AS3 PHP File Upload

**URL:** <https://forum.kirupa.com/t/as3-php-file-upload/318942>\
**Category:** flash\
**Created:** [February 4, 2011, 12:20am UTC](https://forum.kirupa.com/t/as3-php-file-upload/318942 "2011-02-04T00:20:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gemixin](https://avatars.discourse-cdn.com/v4/letter/g/ebca7d/32.png) [@Gemixin](https://forum.kirupa.com/u/Gemixin)\
**Post date:** [February 4, 2011, 12:20am UTC](https://forum.kirupa.com/t/as3-php-file-upload/318942/1 "2011-02-04T00:20:38Z")

</div>

Hi there

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

Flash:

```auto

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
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](http://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
