[eluser]Steve_K[/eluser]
Hi all,
While browsing the Upload class documentation, I came across this statement under preferences:
Quote:file_name None Desired file name
If set CodeIgniter will rename the uploaded file to this name.
This suggests that if I do something like
Code:
$config['file_name'] = 'steve';
my image will be renamed to steve.ext when its copied.
This didn't work for me, however. My result was that the image I uploaded was not added or renamed.
I created a workaround by replacing line 190 in 'Upload.php' in system/libraries with the following code:
Code:
$this->file_name = $this->_prep_filename( (empty($this->file_name) ? $_FILES[$field]['name'] : $this->file_name . $this->get_extension($_FILES[$field]['name'])) );
(I know this is a messy one-liner; I did it to keep constant with the surrounding code...)
Using the above code, my images are renamed properly (as mentioned in the documentation) if I specify something like:
Code:
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '500';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['file_name'] = 'steve';
If my error occurred because I misunderstand the usage of the class, then of course, please disregard and let me know the proper way to achieve what I've described. (FWIW, I also got it by using PHP's rename() function, but I was surprised when the expected config behavior didn't work quite right, so I thought I'd mention it.)
Hope this helps...
Steve K.