0

I followed this question: flash Actionscript 3 and php image upload I copied the code:

 function uploadFile( e:Event ):void
{
fileRef.upload( new URLRequest( "http://localhost/php5dev/test/upload_script.php"  ), "as3File", false );
}

and

<?php

$target = "uploads/" . basename( $_FILES[ "as3File" ][ "name" ] );

if ( move_uploaded_file( $_FILES[ "as3File" ][ "tmp_name" ], $target ) )
    echo( "file upload success<bt />" );
else
    echo( "error uploading file<br />" );
?>

It works great, I just need to know how to save the image under a specific name, how do I pass an argument to the php script? or is that not necessary, can I change it before calling the script?


How would I then call URLrequest to show user the file he uploaded ? Thanks, for any answers!

Community
  • 1
  • 1
Randalfien
  • 396
  • 2
  • 3
  • 17

1 Answers1

1

You could send the filename via a GET query:

fileRef.upload( new URLRequest( "http://localhost/php5dev/test/upload_script.php?filename=myFile.txt"  ), "as3File", false );

And then retrieve it in PHP as $_GET['filename'];

As a word of advice, be careful with those scripts since they are very insecure (one could upload any file to your server and exploit it very easily).

Cay
  • 3,804
  • 2
  • 20
  • 27
  • Thanks very much for this. I though when I have it like thisfileRef.browse([new FileFilter("Images", ".jpg;.jpeg;*.gif;*.png")]); User can only upload images, is this assumption correct? – Randalfien Mar 26 '11 at 17:12
  • Through *your* swf file sure, but I could call your PHP script from anywhere (I could create a new SWF for instance) and upload anything I wanted anywhere I wanted in your server (i.e. if you don't secure it, I could send ?filename=../../../index.php and it could overwrite your main index file)... So yeah, be very careful, and if this is for a live project, I would recommend to hire a backend guy to secure this kind of server-side scripts ;) – Cay Mar 27 '11 at 18:51