Welcome Guest, Not a member yet? Register   Sign In
Codeiginiter and PLupload
#1

[eluser]otn3m3m[/eluser]
Can someone please post an implementation of Codeigniter and plupload?
Please post the controller and view.
thanks
#2

[eluser]Fabdrol[/eluser]
You could try to port it your self from the PLUpload upload.php file.
https://github.com/moxiecode/plupload/bl...upload.php

I'll post it later, but I still think you should have tried yourself first and then posted here what you couldn't get working. We're not here to do your work!
#3

[eluser]DavidBer[/eluser]
Well, I am like the OP trying to figure out how to get plupload going.

I am stuck trying to even get the 'widget' to show up on the page.

I am using carabiner so my code is a little all over the place Smile

controllers/diva
Code:
class Diva extends CI_Controller {

        function __construct()
        {
                parent::__construct();
        }
      
        function index()
        {
                // Load up helpers
                $this->load->helper(array('form', 'url'));
                
                // Load up libraries
                
                $this->load->library('carabiner');
                
                //Setup variables to pass to the views
                $data['breadcrumb'] ='';
                
                //Open up all the views and display the data
                $this->load->view('header_upload');
                $this->load->view('menu');
                $this->load->view('diva',$data);
                $this->load->view('footer');

        }

        function process_upload()
        {
                // Taken from plupload - sample upload file
                $targetDir = base_url() .DIRECTORY_SEPARATOR. "tmpupload";
                $cleanupTargetDir = false; // Remove old files
                $maxFileAge = 60 * 60; // Temp file age in seconds
                
                // 5 minutes execution time
                @set_time_limit(5 * 60);
                
                // Get parameters
                $chunk = isset($_REQUEST["chunk"]) ? $_REQUEST["chunk"] : 0;
                $chunks = isset($_REQUEST["chunks"]) ? $_REQUEST["chunks"] : 0;
                // Clean the fileName for security reasons
                $fileName = preg_replace('/[^\w\._]+/', '', $fileName);
                // Create target dir
                if (!file_exists($targetDir))
                        @mkdir($targetDir);
                // Remove old temp files
                if (is_dir($targetDir) && ($dir = opendir($targetDir))) {
                        while (($file = readdir($dir)) !== false)
                        {
                        $filePath = $targetDir . DIRECTORY_SEPARATOR . $file;
                        // Remove temp files if they are older than the max age
                        if (preg_match('/\\.tmp$/', $file) && (filemtime($filePath) < time() - $maxFileAge)) @unlink($filePath);
                        }
                        closedir($dir);
                        } else
                                die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}');
                // Look for the content type header
                if (isset($_SERVER["HTTP_CONTENT_TYPE"]))
                        $contentType = $_SERVER["HTTP_CONTENT_TYPE"];
                if (isset($_SERVER["CONTENT_TYPE"]))
                        $contentType = $_SERVER["CONTENT_TYPE"];
                if (strpos($contentType, "multipart") !== false)
                {
                        if (isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name']))
                        {
                        // Open temp file
                        $out = fopen($targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab");
                        if ($out)
                        {
                        // Read binary input stream and append it to temp file
                        $in = fopen($_FILES['file']['tmp_name'], "rb");
                                if ($in)
                                {
                                        while ($buff = fread($in, 4096))
                                        fwrite($out, $buff);
                                }
                                else
                                die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
                                fclose($out);
                                unlink($_FILES['file']['tmp_name']);
                        }
                        else
                        die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
                        }
                        else
                                die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}');
                }
                else
                {
                // Open temp file
                $out = fopen($targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab");
                if ($out)
                {
                // Read binary input stream and append it to temp file
                $in = fopen("php://input", "rb");
                if ($in)
                {
                        while ($buff = fread($in, 4096))
                                fwrite($out, $buff);
                }

controllers/header_upload
Code:
<!doctype html>
&lt;html&gt;
&lt;head&gt;
&lt;?php
$this->carabiner->css('wlb.css','screen');
$this->carabiner->css('upload.css','screen');
$this->carabiner->js('gears_init.js');
$this->carabiner->js('plupload.full.min.js');
$this->carabiner->js('jquery.plupload.queue.min.js');
$this->carabiner->js('upload.js');
$this->carabiner->display('jquery');
$this->carabiner->display('both');
?&gt;
&lt;/head&gt;

Continued in next post
#4

[eluser]DavidBer[/eluser]
Continued.
upload.js
Code:
$(function() {
        $("#uploader").plupload({
                // General settings
                runtimes : 'gears,flash,html5',
                url : 'diva/process_upload',
                max_file_size : '1000mb',
                chunk_size : '1mb',
                unique_names : true,

                // Resize images on clientside if we can
                // resize : {width : 320, height : 240, quality : 90},

                // Specify what files to browse for
                filters : [
                        {title : "Document files", extensions : "doc,docx,txt,xls,ppt,pdf"},
                        {title : "Image files", extensions : "jpg,gif,png"},
                        {title : "Video files", extensions : "avi,wmv,qt"},
                        {title : "Audio files", extensions : "mp3,flac"},
                        {title : "Zip files", extensions : "zip"}
                ],

                // Flash settings
                flash_swf_url : 'assets/scripts/plupload.flash.swf',

        });

        // Client side form validation
        $('form').submit(function(e) {
                var uploader = $('#uploader').pluploadQueue();

                // Validate number of uploaded files
                if (uploader.total.uploaded == 0) {
                        // Files in queue upload them first
                        if (uploader.files.length > 0) {
                                // When all files are uploaded submit form
                                uploader.bind('UploadProgress', function() {
                                        if (uploader.total.uploaded == uploader.files.length)
                                                $('form').submit();
                                });

                                uploader.start();
                        } else
                                alert('You must at least upload one file.');

                        e.preventDefault();
                }
        });
});

views/diva

Code:
...
                        <div class="upload">
                        <p>Select some files to upload</p>
                        &lt;?php echo form_open('diva/process_upload'); ?&gt;
                        <div id = "uploader">You need Google Gears, Flash or HTML5</div>
                        &lt;?php form_close(); ?&gt;
                        </div>&lt;!-- end upload div --&gt;

The generated page has all the css/js files and I have clicked to make sure they are there and load.

Anyone have any ideas why I am not even getting the widget to show up? Granted, I have not slept in about 20 hours and am probably just missing something very easy, but I can't find it.

Thanks.
#5

[eluser]dsloan[/eluser]
I tried this with the native code first, and then used this setup (thanks!), but I'm getting the same problem in both - a 404 error where the "url" isn't found. I have debugged and found that my class "uploader" is found ok, but the method is being set to "php", instead of "upload", even though the url clearly states "url: '/uploader/upload'". The method is being overridden somehow.

I have tried to debug other methods which are unrelated to this upload form, which all work fine and the class/method values are as expected.

Any ideas why this is? Have I some configuration setting wrong? I'm using the copied and pasted code from this post, and the [removed] code copied/pasted from the plupload site. All I have changed is my URL.

Thanks,
Diarmid
#6

[eluser]dsloan[/eluser]
Stepping deeper into the debug, I see that in system/core/URI.php within the fetch_uri() method, the URI is being detected as /uploader/php/upload.php. I changed the "url" in the client-side code to /uploader/do_upload' but the URI is still detected as 'uploader/php/upload.php' so that seems to be getting inherited from somewhere.

Not sure if this helps anyone help me?
#7

[eluser]dsloan[/eluser]
I've found the controller part of the URI isn't even actually that url specified in the plupload configuration script, it's just the current controller. It's just appending /php/upload.php to the current controller name. Still no closer to finding out how to set the URI to get it working though.
#8

[eluser]dsloan[/eluser]
Got this sorted. The configuration parameters weren't being initialized and picked up in the HTML file, they were being overridden by a custom JS file.
#9

[eluser]Mr-H[/eluser]
try this
http://vortexdev.netii.net/article_13/In...odeIgniter




Theme © iAndrew 2016 - Forum software by © MyBB