Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3663030
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:29:02+00:00 2026-05-19T01:29:02+00:00

I am trying to implement a multiple file upload script to codeigniter. the script

  • 0

I am trying to implement a multiple file upload script to codeigniter. the script can be find here
http://valums.com/ajax-upload/. I find it quite good, so I decide to put in current apps.

The problem is, I couldn’t access the uploaded files with codeigniter. If you a codeigniter developer please advise how I could grap the file send by the script ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:29:02+00:00Added an answer on May 19, 2026 at 1:29 am

    CodeIgniter has a few ways to handle uploads, but since your ajax-upload script already has a handler, you should use that.

    How to:

    Create a new file in your application/libraries folder, named Qqfileuploader.php and paste this in it:

    <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
        class Qqfileuploader {
            private $allowedExtensions = array();
            private $sizeLimit = 10485760;
            private $file;
    
            function __construct(array $allowedExtensions = array(), $sizeLimit = 10485760){        
                $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_size and upload_max_filesize to $size'}");    
                }        
            }
    
            private function toBytes($str){
                $val = trim($str);
                $last = strtolower($str[strlen($str)-1]);
                switch($last) {
                    case 'g': $val *= 1024;
                    case 'm': $val *= 1024;
                    case 'k': $val *= 1024;        
                }
                return $val;
            }
    
            /**
             * Returns array('success'=>true) or array('error'=>'error message')
             */
            function handleUpload($uploadDirectory, $replaceOldFile = FALSE){
                if (!is_writable($uploadDirectory)){
                    return array('error' => "Server error. Upload directory isn't writable.");
                }
    
                if (!$this->file){
                    return array('error' => 'No files were uploaded.');
                }
    
                $size = $this->file->getSize();
    
                if ($size == 0) {
                    return array('error' => 'File is empty');
                }
    
                if ($size > $this->sizeLimit) {
                    return array('error' => 'File is too large');
                }
    
                $pathinfo = pathinfo($this->file->getName());
                $filename = $pathinfo['filename'];
                //$filename = md5(uniqid());
                $ext = $pathinfo['extension'];
    
                if($this->allowedExtensions && !in_array(strtolower($ext), $this->allowedExtensions)){
                    $these = implode(', ', $this->allowedExtensions);
                    return array('error' => 'File has an invalid extension, it should be one of '. $these . '.');
                }
    
                if(!$replaceOldFile){
                    /// don't overwrite previous files that were uploaded
                    while (file_exists($uploadDirectory . $filename . '.' . $ext)) {
                        $filename .= rand(10, 99);
                    }
                }
    
                if ($this->file->save($uploadDirectory . $filename . '.' . $ext)){
                    return array('success'=>true);
                } else {
                    return array('error'=> 'Could not save uploaded file.' .
                        'The upload was cancelled, or server error encountered');
                }
    
            }    
        }
    

    Now, in the controller that you’re uploading to, do this:

    // list of valid extensions, ex. array("jpeg", "xml", "bmp")
    $allowedExtensions = array();
    // max file size in bytes
    $sizeLimit = 10 * 1024 * 1024;
    
    $this->load->library("Qqfileuploader",array($allowedExtensions, $sizeLimit));
    $this->Qqfileuploader->handleUpload('uploads/');
    // to pass data through iframe you will need to encode all html tags
    echo htmlspecialchars(json_encode($result), ENT_NOQUOTES);
    

    That should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use valums ajax uploader. http://valums.com/ajax-upload/ I have the following on my
I am trying to implement a multiple file upload where I am right now
I'm using Rails 3.1 with Paperclip and trying to implement Uploadify for multiple file
I'm really novice with ActionScript and Flash/Flex. I'm trying to implement a multiple file
I'm trying to implement the jQuery File Upload Widget on my website. What I
With HTML 5 i am trying to implement the file upload functionality. Now if
I am trying to implement the multiple uploading to Amazon S3 https://github.com/jnicklas/carrierwave/blob/master/README.md (under Using
I'm trying to implement upload code for grails. When the file is processed on
I was trying to implement Multiple DB connected Fluent NHibernate sample Application . My
I am trying to implement a multiple choice quiz and will want to store

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.