Codeiginiter and PLupload - El Forum - 11-03-2010
[eluser]otn3m3m[/eluser]
Can someone please post an implementation of Codeigniter and plupload?
Please post the controller and view.
thanks
Codeiginiter and PLupload - El Forum - 01-25-2011
[eluser]Fabdrol[/eluser]
You could try to port it your self from the PLUpload upload.php file.
https://github.com/moxiecode/plupload/blob/master/examples/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!
Codeiginiter and PLupload - El Forum - 02-24-2011
[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
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>
<html>
<head>
<?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');
?>
</head>
Continued in next post
Codeiginiter and PLupload - El Forum - 02-24-2011
[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>
<?php echo form_open('diva/process_upload'); ?>
<div id = "uploader">You need Google Gears, Flash or HTML5</div>
<?php form_close(); ?>
</div><!-- end upload div -->
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.
Codeiginiter and PLupload - El Forum - 01-24-2012
[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
Codeiginiter and PLupload - El Forum - 01-24-2012
[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?
Codeiginiter and PLupload - El Forum - 01-25-2012
[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.
Codeiginiter and PLupload - El Forum - 01-25-2012
[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.
Codeiginiter and PLupload - El Forum - 01-26-2012
[eluser]Mr-H[/eluser]
try this
http://vortexdev.netii.net/article_13/Integrate_Plupload_with_CodeIgniter
|