CodeIgniter-Multi-Upload icon indicating copy to clipboard operation
CodeIgniter-Multi-Upload copied to clipboard

$config['file_name'] doesn't work

Open riscphree opened this issue 12 years ago • 5 comments

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

riscphree avatar Oct 23 '13 19:10 riscphree

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

stvnthomas avatar Oct 23 '13 20:10 stvnthomas

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

riscphree avatar Oct 23 '13 20:10 riscphree

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

stvnthomas avatar Oct 23 '13 21:10 stvnthomas

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

riscphree avatar Oct 23 '13 21:10 riscphree

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.

stvnthomas avatar Oct 24 '13 22:10 stvnthomas