0

I have blueimp file upload working well with codeigniter. I use the UploadHandler library as is. But I want to extend it to replace two functions that create the unique filename. The code for this is in the BlueImp Github wiki.

I created an extended library thus:

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

class MY_UploadHandler extends UploadHandler {

public function __construct() {
    parent::__construct();
    $CI =& get_instance();
    $CI->load->library('UploadHandler');
}   

protected function upcount_name_callback($matches) {
    $index = isset($matches[1]) ? intval($matches[1]) + 1 : 1;
    $ext = isset($matches[2]) ? $matches[2] : '';
    return '-'.$index.''.$ext;
}

protected function upcount_name($name) {
    return preg_replace_callback(
    '/(?:(?:-([\d]+))?(\.[^.]+))?$/',
    array($this, 'upcount_name_callback'),
    $name,
    1
    );
}

}

When I try to run it, I get an 'unable to load UploadHandler' error. If I remove my MY extension, the original code runs. What is wrong with my extension code? Isn't this the proper way to extend CI libraries?

And, yes, the filename for my file is MY_UploadHandler.php

Thanks!

4

1 回答 1

1

I noodled over this for a while and finally figured it out. To extend a custom library, you need to 'require once' the file it is extending, prior to the definition of the class.

EX:

require_once("UploadHandler.php");

class MY_UploadHandler extends UploadHandler
{
}

Hopefully that helps.

于 2013-09-19T13:39:38.597 回答