[eluser]chamil sanjeewa[/eluser]
view
Code:
<div id="file-uploader-demo1">
<noscript>
<p>Please enable JavaScript to use file uploader.</p>
<!-- or put a simple form for upload here -->
</noscript>
</div>
<div style="background:#000000;width: 200px;height: 100px;" id="do_uploade">
</div>
<!--<img src="http://192.168.1.99/test/photo.php?image=1303252442.jpg&w=200&h=800"/>-->
[removed]config->item('3rd');?>jquery/valums/fileuploader.js">[removed]
[removed]
function createUploader(){
var uploader = new qq.FileUploader({
element: document.getElementById('file-uploader-demo1'),
action: 'http://192.168.1.99/futureid/gallery/upload/multi_uplode',
debug: true
});
}
// in your app create uploader as soon as the DOM is ready
// don't wait for the window to load
window.onload = createUploader;
[removed]
<?php include_once (APPPATH . 'views/common/merchant/co_footer.php'); ?>
controllers:
Code:
function multi_uplode() {
$this->load->model('gallery/Upload_Model');
$this->Upload_Model->ftp_path = 'futureid_media/merchant/gallery';
$this->Upload_Model->temp_path = APPPATH . '../../files/temp/';
$this->Upload_Model->allowedExtensions = array("jpeg","jpg");
$this->Upload_Model->sizeLimit = 20480000;
$result = $this->Upload_Model->handleUpload();
// to pass data through iframe you will need to encode all html tags
echo htmlspecialchars(json_encode($result), ENT_NOQUOTES);
}
Model :
Code:
<?php
/**
* Handle file uploads via XMLHttpRequest
*/
class qqUploadedFileXhr {
/**
* 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);
if ($realSize != $this->getSize()) {
return false;
}
$target = fopen($path, "w");
fseek($temp, 0, SEEK_SET);
stream_copy_to_stream($temp, $target);
fclose($target);
return true;
}
function getName() {
return $_GET['qqfile'];
}
function getSize() {
if (isset($_SERVER["CONTENT_LENGTH"])) {
return (int) $_SERVER["CONTENT_LENGTH"];
} else {
throw new Exception('Getting content length is not supported.');
}
}
}
/**
* Handle file uploads via regular form post (uses the $_FILES array)
*/
class qqUploadedFileForm {
/**
* Save the file to the specified path
* @return boolean TRUE on success
*/
function save($path) {
if (!move_uploaded_file($_FILES['qqfile']['tmp_name'], $path)) {
return false;
}
return true;
}
function getName() {
return $_FILES['qqfile']['name'];
}
function getSize() {
return $_FILES['qqfile']['size'];
}
}
class Upload_Model extends CI_Model {
public $allowedExtensions = array();
public $sizeLimit;
private $file;
public $ftp_path;
public $temp_path;
public $user_id;
function __construct() {
parent::__construct();
$this->load->config('masterdb_config', TRUE); // lode data base table
$this->mas_tables = $this->config->item('masterdb_config'); // get masetr table array
$this->load->library('session');
$this->load->database();
$this->user_id = $this->session->userdata('profile_id');
$allowedExtensions = $this->allowedExtensions;
$sizeLimit = $this->sizeLimit;
$allowedExtensions = array_map("strtolower", $allowedExtensions);
// $this->allowedExtensions = $allowedExtensions;
// $this->sizeLimit = $sizeLimit;
$this->checkServerSettings();
if (isset($_GET['qqfile'])) {
$this->file = new qqUploadedFileXhr();
} elseif (isset($_FILES['qqfile'])) {
$this->file = new qqUploadedFileForm();
} else {
$this->file = false;
}
}
private function checkServerSettings() {
$postSize = $this->toBytes(ini_get('post_max_size'));
$uploadSize = $this->toBytes(ini_get('upload_max_filesize'));
if ($postSize < $this->sizeLimit || $uploadSize < $this->sizeLimit) {
$size = max(1, $this->sizeLimit / 1024 / 1024) . 'M';
die("{'error':'increase post_max_