stvnthomas / CodeIgniter-Multi-Upload

Multiple file upload support for CodeIgniter 2.x.
151 stars 158 forks source link

$config['file_name'] doesn't work #5

Open riscphree opened 11 years ago

riscphree commented 11 years ago

When trying to set new filename for uploads (single and multiple) setting the CI config 'file_name' it doesn't seem to work with this. Instead it rather uses the original file names and won't allow me to set my own filenames :(

stvnthomas commented 11 years ago

How are you setting your filename(s)? Can you post your code?

riscphree commented 11 years ago

I'm setting like this:

$file_name = md5(time());
$config['file_name'] = $file_name.".png";

and then doing regular upload as such:

$this->load->library('upload', $config);
if(!$this->upload->do_multi_upload($field_name)){
// failed
$error = array('error' => $this->upload->display_errors());
}else{

etc, etc

stvnthomas commented 11 years ago

Try passing the filename through as an array - $config["file_name"] = array("{$file_name}.png"). Let me know if this helps.

riscphree commented 11 years ago

That seems to have worked. Why does that work and not simple setting it like normal?

stvnthomas commented 11 years ago

That's a very good question!

It's looking for an array of filenames because there's the potential for more than one file and filename. The library does fallback to the native do_upload() method if only a single file is uploaded but doesn't set the singular filename override for it (see lines 77-93). I'll see if I can come up with a update to make it a little more intelligent when falling back.