Welcome Guest, Not a member yet? Register   Sign In
CI + valum uploader problem
#1

[eluser]Vega[/eluser]
Hi guys, I'm having some problems implementing the latest version of valums file uploader with CI (http://valums.com/ajax-upload/).

In the server/php.php file I modified the __construct() method and added an initialize method instead so it could be used as a library, everything else is the same:

qqFileUploader.php library modification:
Code:
function __construct(){        
        // $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;
        }
    }
    
/**
  * Initialize Preferences
  *
  * @access public
  * @param array initialization parameters
  * @return void
  */
public function initialize($params = array())
{
  if (count($params) > 0)
  {
   foreach ($params as $key => $val)
   {
    if (isset($this->$key))
    {
     $this->$key = $val;
    }
   }
  }
}

Controller:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Upload extends MY_Controller {

public function __construct()
{
  parent::__construct();
}

public function do_upload()
{
  $config = array();
  $config['sizeLimit'] = 10 * 1024 * 1024;
  $config['allowedExtensions'] = array();
  
  $this->load->library('qqfileuploader');
  $this->qqfileuploader->initialize($config);
  $result = $this->qqfileuploader->handleUpload('/Applications/MAMP/htdocs/ci/cmx/res/uploads/');
  echo htmlspecialchars(json_encode($result), ENT_NOQUOTES);
}

public function form()
{
  $this->load->view('uploader_test/index');
}
}

/* End of file upload.php */
/* Location: ./application/controllers/Upload.php */

View file:
Code:
<!DOCTYPE html>
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
&lt;link href="&lt;?php echo site_url('res/css/fileuploader.css'); ?&gt;" rel="stylesheet" type="text/css"&gt;
&lt;style&gt;    
  body {font-size:13px; font-family:arial, sans-serif; width:700px; margin:100px auto;}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;  
<p><a href="http://github.com/valums/file-uploader">Back to project page</a></p>

<p>To upload a file, click on the button below. Drag-and-drop is supported in FF, Chrome.</p>
<p>Progress-bar is supported in FF3.6+, Chrome6+, Safari4+</p>

<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>

[removed][removed]
[removed]        
function createUploader(){            
   var uploader = new qq.FileUploader({
    element: document.getElementById('file-uploader-demo1'),
    action: 'http://localhost:8888/ci/cmx/upload/do_upload/',
    debug: true,
    allowedExtensions: ['jpg', 'jpeg', 'png', 'gif']
   });          
  }
  
  // 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;/body&gt;
&lt;/html&gt;

I have tested directory permissions and they seem to be all correct and the uploader works outside CI.

I get this error in the browser console after trying to upload something:
[uploader] xhr - server response received - fileuploader.js:873
[uploader] responseText = {"error":"No files were uploaded."} - fileuploader.js:873

Any ideas?




Theme © iAndrew 2016 - Forum software by © MyBB