Welcome Guest, Not a member yet? Register   Sign In
andrew valums ajax upload to codeigniter
#10

[eluser]chamil sanjeewa[/eluser]
view

Code:
<div id="file-uploader-demo1">
        <noscript>
            <p>Please enable JavaScript to use file uploader.</p>
            &lt;!-- or put a simple form for upload here --&gt;
        </noscript>
    </div>


<div style="background:#000000;width: 200px;height: 100px;" id="do_uploade">


</div>
&lt;!--<img src="http://192.168.1.99/test/photo.php?image=1303252442.jpg&w=200&h=800"/>--&gt;

[removed]config->item('3rd');?&gt;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]

&lt;?php include_once (APPPATH . 'views/common/merchant/co_footer.php'); ?&gt;



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:
&lt;?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_


Messages In This Thread
andrew valums ajax upload to codeigniter - by El Forum - 12-15-2010, 03:10 AM
andrew valums ajax upload to codeigniter - by El Forum - 12-15-2010, 07:00 AM
andrew valums ajax upload to codeigniter - by El Forum - 01-05-2011, 02:56 PM
andrew valums ajax upload to codeigniter - by El Forum - 04-20-2011, 11:16 PM
andrew valums ajax upload to codeigniter - by El Forum - 04-21-2011, 01:47 AM
andrew valums ajax upload to codeigniter - by El Forum - 04-21-2011, 08:52 AM
andrew valums ajax upload to codeigniter - by El Forum - 05-15-2011, 09:44 AM
andrew valums ajax upload to codeigniter - by El Forum - 05-18-2011, 01:03 AM
andrew valums ajax upload to codeigniter - by El Forum - 05-18-2011, 02:56 AM
andrew valums ajax upload to codeigniter - by El Forum - 05-19-2011, 06:24 AM
andrew valums ajax upload to codeigniter - by El Forum - 05-19-2011, 06:50 AM
andrew valums ajax upload to codeigniter - by El Forum - 05-19-2011, 06:56 AM
andrew valums ajax upload to codeigniter - by El Forum - 05-23-2011, 11:18 AM
andrew valums ajax upload to codeigniter - by El Forum - 05-28-2011, 05:58 AM
andrew valums ajax upload to codeigniter - by El Forum - 05-28-2011, 06:05 AM
andrew valums ajax upload to codeigniter - by El Forum - 01-26-2012, 04:27 PM
andrew valums ajax upload to codeigniter - by El Forum - 01-27-2012, 05:43 PM
andrew valums ajax upload to codeigniter - by El Forum - 02-01-2012, 08:07 AM
andrew valums ajax upload to codeigniter - by El Forum - 02-01-2012, 08:18 AM
andrew valums ajax upload to codeigniter - by El Forum - 02-01-2012, 09:09 AM
andrew valums ajax upload to codeigniter - by El Forum - 02-01-2012, 10:23 AM



Theme © iAndrew 2016 - Forum software by © MyBB