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

[eluser]runrun[/eluser]
Hello,

http://valums.com/ajax-upload/

Did anyone successfully implement andrew valums's upload to codeigniter ? Would you like to give me some tips ?

My problem implementing is, the script sends a query string to server instead of segment URI, therefore, I don't know how to handle with codeigniter.
#2

[eluser]SPeed_FANat1c[/eluser]
I have used it few months ago and I guess this was then older version of this plugin. It worked with post. I did not find any code line where I enable post or something like that. Maybe in new version it is something differrent.

Edit:
Just took a look at the chrome console, when I upload it writes :

Failed to load resource

and on the right side the url to the upload function.

But it still works Big Grin strange
#3

[eluser]Danes[/eluser]
To use this you will need to enable query strings as explained here: http://ellislab.com/codeigniter/user-gui.../urls.html .

Check this post: http://ellislab.com/forums/viewthread/177158/

Sorry, the forum does not currently allow the posting of links.
#4

[eluser]seibelj[/eluser]
Here's how to use the latest Valums Ajax Uploader with the progress bar:

Download latest one here: http://valums.com/ajax-upload/

Extract the download. In the extracted folder is the server folder, and inside that is a file named php.php

Put php.php in your application/libraries folder and rename it qquploadedfilexhr.php

Delete the final lines that are not part of any class (line 154 and after in my version).

Create a controller function for where you want the uploader action to be. Inside the function put this code:

Code:
$this->load->library('qquploadedfilexhr');

// list of valid extensions, ex. array("jpeg", "xml", "bmp")
$allowedExtensions = array('txt');
// max file size in bytes
$sizeLimit = 1 * 1024 * 1024;

$uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
$result = $uploader->handleUpload('YOUR PATH TO UPLOAD FOLDER');
// to pass data through iframe you will need to encode all html tags
echo htmlspecialchars(json_encode($result), ENT_NOQUOTES);

Change the file extensions and size to what you want, and you MUST put in the correct path to the upload folder (mine is /var/www/website-name/www/uploads).

Include the javascript and CSS files on your page, and this in your markup where you want the upload button:

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

Create a new javascript file and put this in it, and include it on your page:

Code:
$(document).ready(function() {
    var uploader = new qq.FileUploader({
        // pass the dom node (ex. $(selector)[0] for jQuery users)
        element: document.getElementById('file-uploader'),
        // path to server-side upload script
        action: 'FULL PATH TO UPLOAD FUNCTION'
    });
});

Change action: 'FULL PATH TO UPLOAD FUNCTION' to the server route, like http://localhost/index.php/controller_na...d_function.

This works fine for me, let me know if you have any problems. Make sure to increase the max file upload size in php.ini to the max size you set for the upload, or you'll get an error.
#5

[eluser]runrun[/eluser]
I've no longer used this upload script, I have created an html5 upload script that suits my need better, and it's easier to use.
#6

[eluser]seibelj[/eluser]
I don't think an HTML5 upload script will be backwards compatible with older versions of ANY browser, not just IE.
#7

[eluser]predat0r[/eluser]
seibelj, can you tell me what to type for upload path because I cant figure out.. I use wamp at localhost so
c:/wamp/www/sitename/..

and what to type if I go online? and cant see what are my server directories

thanks!
#8

[eluser]SPeed_FANat1c[/eluser]
$config['upload_path'] = './uploads/';

we use relational path for file uploading. In my example the uploads folder is in the root directory.
#9

[eluser]predat0r[/eluser]
[quote author="SPeed_FANat1c" date="1305720196"]$config['upload_path'] = './uploads/';

we use relational path for file uploading. In my example the uploads folder is in the root directory.[/quote]

thx!
#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_




Theme © iAndrew 2016 - Forum software by © MyBB