-3

im using plupload( http://www.plupload.com/index.php ) and i would like to know how can i pass variables in the form to the upload.php file , i tried this:

<form  method="post" action="dump.php">
<input type="text" id="event_id"/>
    <div id="uploader">
        <p>You browser doesn't have Flash, Silverlight, Gears, BrowserPlus or HTML5 support.</p>
    </div>
</form>



$(function() {
    $("#uploader").plupload({
        // General settings
        runtimes : 'flash,html5,browserplus,silverlight,gears,html4',
        url : '../upload.php?event_id='+$("#event_id").val(),
        max_file_size : '1000mb',
        max_file_count: 20, // user can add no more then 20 files at a time
        chunk_size : '1mb',
        unique_names : false,

like this(passing the var in a query string) does not work.

tetris
  • 4,302
  • 6
  • 28
  • 41
  • 1
    What do you mean "does not work"? Can we see your `upload.php` and what you are trying to do with the query string/`$_GET` vars? Do you have Firebug installed? If not, you should, or this will be hard to debug. – Wesley Murch Oct 21 '11 at 18:01
  • the upload.php is the original one, i had just change this(to see if the var in the query string was sent), but nothing happened: $targetDir = 'uploads/'.$_GET["event_id"].'/'; – tetris Oct 21 '11 at 18:04
  • Try hardcoding a value first: `$targetDir = 'uploads/3/';` and see if that works, it could be a permissions issue creating the directory. Also, open the Firebug console and do a `exit(print_r($_GET))` in your php script and see what happens. – Wesley Murch Oct 21 '11 at 18:08
  • OK and what about the `print_r()`? Read the whole comment. – Wesley Murch Oct 21 '11 at 18:13
  • how do you echo a print r in firebug? – tetris Oct 21 '11 at 18:17
  • You don't, you do it in your PHP script and view the response in the Firebug console. Each chunk of each file will send a request, and each request will get a response. – Wesley Murch Oct 21 '11 at 18:19
  • ok i put this in the uploads.php but nothing happens in the console – tetris Oct 21 '11 at 19:00
  • "Nothing" happens? I really doubt that. You have an answer, why don't you try that - it looks correct to me. – Wesley Murch Oct 21 '11 at 19:05

3 Answers3

11

Maybe with the multipart_params option? Found in the documentation.

multipart_params: {event_id : $("#event_id").val(), param2 : 'value2'}

Use $_REQUEST['event_id'] to get the event id.

scessor
  • 15,995
  • 4
  • 43
  • 54
  • by the way i still cant fix the problem , it's very very hard. – tetris Oct 21 '11 at 23:15
  • `$_REQUEST` is the answer, ladies and gents. you can tack on multipart_params and keep looking for them in $_POST until you lose your mind, or you can look at $_REQUEST as I just did, finally, at long, long, last. thank you for this answer! – David Mar 31 '16 at 20:03
4

If you want to send different parameters for each file just do it like that:

uploader.bind('BeforeUpload', function(up, file) {
    up.settings.multipart_params = {"fileid": file.id };
});
Mateusz
  • 1,179
  • 10
  • 15
  • Hi, Can you tell me where should I put this bit of code? i mean should i use $('#uploader').bind(...) – SIDU Feb 18 '16 at 02:38
0

This is how I did it. I don't think its very hard :)

uploader.bind('BeforeUpload', function(up, file) {
    up.settings.url =  url+"?plupload_id="+file.id;
});

to get it:

if(isset($_GET['plupload_id']))$id = $_GET['plupload_id'];
  • Thanks, good idea. But it adds multiple parameters. Better solution - use UploadFile method instead – ymakux Feb 19 '15 at 04:26