views:

144

answers:

2

Hi,

I am trying to extend the Upload library in CodeIgniter. I have been trying all morning, following various tuts and forum posts, but can't get it to work.

If I add the function I want directly into the Upload.php library, it works-- but I know this isn't the right way, and want to do it right since I'm doing it.

Here is the content of the extension [system/application/libraries/MY_Upload.php]:

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

class MY_Upload extends Upload{
function MY_Upload(){
    parent::Upload();
}
  function mupload($configs,$files){
    if(count($configs) != count($files)){
       return 'array_count_wrong';
    }
$retArr=array();
    for($i=0, $j = count($files);$i<$j;$i++){
        $this->initialize($configs[$i]);
        if(!$this->do_upload($files[$i])){
            array_push($retArr,$this->display_errors());
        }else{
            array_push($retArr,'OK');
        }
    }
    return($retArr);
}

?>

And relevant controller code:

$this->load->library('upload');
$messages=$this->upload->mupload($config,$files);

It fails with no indication of why.

What am I doing wrong?

Thx.

+1  A: 

Missing a friggin } at the end of the extension

:'(

I REALLY REALLY REALLY wish there was a way to get more informative error messages (or any message at all) when things fail...

stormdrain
You could enable PHP error reporting (http://www.php.net/manual/en/errorfunc.configuration.php#ini.error-reporting) while in a development environment; also, using a good editor or IDE with proper syntax highlighting will help you catch syntax errors like the one you described.
Bauer
error reporting is most definitely on. Set to 11, even. I use TextMate (which I lub), but it doesn't seem to highlight blocks, just functions, vars, arrays, etc. It'll blink if you try and put a closing bracket with no matching opening bracket, but doesn't really help when dealing with 10k lines of code. Thanks.
stormdrain
A: 

A few extra bits of advice here.

  1. You should extend from CI_Upload not Upload
  2. You only need to add a contructor with parent::CI_Upload; if you are actually doing something in your controller. Delete function MY_Upload() as you don't need it. :-)

Glad you solved your main problem though!

Phil Sturgeon
Indeedidly. I had the CI_ in there most of the time, but not when I copied the code to paste here. It's in there now :) I also deleted the MY_Upload function. Though I'm not clear why... You said "if you're actually doing something in your controller". I think I'm doing stuff in my controller, aren't I? Do you mean calling functions in the parent class directly inside the controller? Thx.
stormdrain
Sorry replace the word controller with constructor. Basically if you create your own constructor then you need to cal the parents constructor first as when you make a function in the child of an inherited class you are essentially replacing it. If you are not using a constructor in your MY_ class, then you do not need to put an empty constructor in. :-)
Phil Sturgeon