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');
}
}
开发者_如何学JAVA 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.
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...
A few extra bits of advice here.
- You should extend from CI_Upload not Upload
- 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!
精彩评论