integrate plupload to my media plugin

I use buddypress activity plus as a media plugin. The plugin uses valums-file-upload for uploading media, I want to add plupload and remove valums-file-upload. What I have done so far:
Removed this section,

var uploader = new qq.FileUploader({
        "element": $('#med_tmp_photo')[0],
        //"listElement": $('#med_tmp_photo_list')[0],
        "allowedExtensions": ['jpg', 'jpeg', 'png', 'gif'],
        //"action": ajaxurl,
        "params": {
            "action": "med_preview_photo"
        },

        "onComplete": createPhotoPreview,
        template: '<div class="qq-uploader">' +
            '<div class="qq-upload-drop-area"><span>' + broadcast.drop_files + '</span></div>' +
            '<div class="qq-upload-button">' + broadcast.upload_file + '</div>' +
            '<ul class="qq-upload-list">' +
         '</div>'
    });

and added,

Read More
var uploader = new plupload.Uploader({
            runtimes : 'html5,flash,silverlight', // Set runtimes, here it     will use HTML5, if not supported will use flash, etc.
            browse_button : 'pickfiles', // The id on the select files button
            multi_selection: false, // Allow to select one file each time
            container : 'uploader', // The id of the upload form container
            max_file_size : '800mb', // Maximum file size allowed
            url : //'upload.php', // The url to the upload.php file

             resize: {width: 300,height: 300,quality: 70},

            flash_swf_url : 'js/plupload.flash.swf', // The url to thye flash file
            silverlight_xap_url : 'js/plupload.silverlight.xap', // The url to the silverlight file
            filters : [ {title : "Image files", extensions : "jpg,gif,png,jpeg"} ] // Filter the files that will be showed on the select files window

    });

        // RUNTIME
        uploader.bind('Init', function(up, params) {
            $('#runtime').text(params.runtime);
        });

        // Start Upload ////////////////////////////////////////////
        // When the button with the id "#uploadfiles" is clicked the upload will start
        $('#med_submit').click(function(e) {
            uploader.start();
            e.preventDefault();
});

and changed file_uploader.php to the following,

class plupload_1 {
/**
 * Save the file to the specified path
 * @return boolean TRUE on success
 */
function save($path) {
    $input = fopen("php://input", "r");
    $temp = tmpfile();
    $realSize = stream_copy_to_stream($input, $temp);
    fclose($input);

    $target = fopen($path, "w");
    fseek($temp, 0, SEEK_SET);
    stream_copy_to_stream($temp, $target);
    fclose($target);

    return true;
}

}

/**
 * Handle file uploads via regular form post (uses the $_FILES array)
 */

class plupload_2 {

function __construct(){

        $this->file = new plupload_1();

}

finally changed the ‘ajax_preview_photo’ in ‘class_bpfb_binder.php’

from this,

function ajax_preview_photo () {
    $dir = BPFB_PLUGIN_BASE_DIR . '/img/';
    require_once(BPFB_PLUGIN_BASE_DIR . '/lib/external/file_uploader.php');
    $uploader = new qqFileUploader(array('jpg', 'jpeg', 'png', 'gif'));
    $result = $uploader->handleUpload(BPFB_TEMP_IMAGE_DIR);
    //header('Content-type: application/json'); // For some reason, IE doesn't like this. Skip.
    echo htmlspecialchars(json_encode($result), ENT_NOQUOTES);
    exit();
}

to this,

  function ajax_preview_photo () {
    //$dir = BPFB_PLUGIN_BASE_DIR . '/img/';
    require_once(BPFB_PLUGIN_BASE_DIR . '/lib/external/file_uploader.php');
    $uploader = new plupload_2();
    $result = $uploader->PlupLoad(BPFB_TEMP_IMAGE_DIR);
    //header('Content-type: application/json'); // For some reason, IE doesn't like this. Skip.
    echo htmlspecialchars(json_encode($result), ENT_NOQUOTES);
    exit();
} 

but I am not sure what I am doing is correct or if there is a different approach, any help will be appreciated.

Thank You

Related posts

1 comment

Comments are closed.