1 (edited by kochero 2016-03-12 01:41:38)

Topic: Pass variable from form url and write it to mysql

Hello everyone,

I'm so new in Plupload and I have a problem, I tried to get a solution but I could not. I tried everything and search on forum here also stackoverflow...

I want to write some values to database after upload. I can write to database filename, filesize and filetype. But I can't write variable from the url which have plupload form and it is called: swap_id...

This is an example for this kinds of url: http://localhost/public/add_swap_photos.php?swap_id=2

Here is my code I tried these things:

$(function() {
    $("#uploader").plupload({
        // General settings
        runtimes : 'html5,flash,silverlight,html4',
        
//I changed url setting from only upload.php to this:
        
        url : 'upload.php?swap_id='+$("#swap_id").val(),

//Also I added this two lines
        
        multipart: true,
        
        multipart_params: { 'swap_id': $("#swap_id").val() }
            
        // User can upload no more then 20 files in one go (sets multiple_queues to false)
        max_file_count: 20,
        
        chunk_size: '1mb',

        // Resize images on clientside if we can
        resize : {
            width : 800, 
            height : 800, 
            quality : 90,
            crop: true // crop to exact dimensions
        },
        
        filters : {
            // Maximum file size
            max_file_size : '1000mb',
            // Specify what files to browse for
            mime_types: [
                {title : "Image files", extensions : "jpg,gif,png"},
                {title : "Zip files", extensions : "zip"}
            ]
        },

        // Rename files by clicking on their titles
        rename: true,
        
        // Sort files
        sortable: true,

        // Enable ability to drag'n'drop files onto the widget (currently only HTML5 supports that)
        dragdrop: true,

        // Views to activate
        views: {
            list: true,
            thumbs: true, // Show thumbs
            active: 'thumbs'
        },

        // Flash settings
        flash_swf_url : '../../js/Moxie.swf',

        // Silverlight settings
        silverlight_xap_url : '../../js/Moxie.xap',
    });

//Also I added these two lines
    
    uploader.bind('BeforeUpload', function(up,file){
    up.settings.url = 'upload.php?swap_id='+$("#swap_id").val()
    });    
    
    // Handle the case when form was submitted before uploading has finished
    $('#form').submit(function(e) {
        // Files in queue upload them first
        if ($('#uploader').plupload('getFiles').length > 0) {
        
            // When all files are uploaded submit form
            $('#uploader').on('complete', function() {
            $('#form')[0].submit();
            });
            $('#uploader').plupload('start');
        } else {
            alert("You must have at least one file in the queue.");
        }
        return false; // Keep the form from submitting
    });
});
</script>

And I try to get this data on upload.php like that:

$swap_id = $_REQUEST["swap_id"];

I tried also too much things but the last changes are above...

Please help me, I just want to get an variable from URL, and that is "swap_id" and
This variable is in this URL: http://localhost/public/add_swap_photos.php?swap_id=2

I hope I can explain my problem well and someone can help me to fix this issue...

Thank you so much...

Re: Pass variable from form url and write it to mysql

Anybody help?