Welcome Guest, Not a member yet? Register   Sign In
file upload class - problem with file_name config item
#1

[eluser]Berik[/eluser]
Hi there,

Not sure if this is a bug or a misunderstanding on my part but when initialising the upload class with the file_name config item, the uploaded file is not renamed to what I feed it (it keeps the original file name).

Here's my upload function (within a controller):

Code:
function _upload()
    {
        $config['allowed_types'] = 'jpg|jpeg|gif|png';
        $config['upload_path'] = './uploads/';
        $config['file_name'] = 'name_of_file';
        $config['overwrite'] = FALSE;

        $this->load->library('upload', $config);
        if( ! $this->upload->do_upload('files'))
        {
            var_dump($this->upload->display_errors());
            exit;
        }

        // all ok, return file upload data
        $file_data = $this->upload->data();
        return $file_data;
    }

Any clue on what I could be doing wrong?
#2

[eluser]vaxis[/eluser]
Try to remove $config['overwrite'] = FALSE; and see if you have same problem.
#3

[eluser]Berik[/eluser]
[quote author="vaxis" date="1275055944"]Try to remove $config['overwrite'] = FALSE; and see if you have same problem.[/quote]

yup, same problem Sad

On a sidenote, the reason why I'm using $config['overwrite'] = FALSE is because this will become a multiple file upload (once I get it working on a single file) and this directive increments the file names. Just thought I should make a precision on that Smile
#4

[eluser]vaxis[/eluser]
See the code below(i use it for uploading one image) hope it will help you.

Code:
# CATEGORY IMAGE
        $this->load->helper('string');
        $img_name = url_title($category_name).'_'.random_string('alnum', 5);

        $filename = $_FILES['userfile']['name'];
        $ext = substr($filename, strrpos($filename, '.') + 1);

        $gallery_path = realpath(APPPATH . '../uploads');

        $config['upload_path'] = $gallery_path . '/categories';
        $config['allowed_types'] = 'gif|jpg|jpeg|png';
        $config['max_size'] = '2000';
        $config['file_name'] = $img_name;

        $this->load->library('upload', $config);
        if( ! $this->upload->do_upload())
        {
            $this->session->set_flashdata('error', $this->upload->display_errors());
            redirect('admin/add_category', 'refresh');
        }
        $image_data = $this->upload->data();
#5

[eluser]Clooner[/eluser]
Make sure it is a filename without the fileextension!
#6

[eluser]Berik[/eluser]
Thanks vaxis, had to rush out so didn't have time to try your code... will do that asap and come back to post the results.
#7

[eluser]Berik[/eluser]
Tried your script vaxis and still no renaming... arghhh!
Could be me but I believe there's a bug with the file_name config item.

I guess I'll just have to correctly name my files before uploading them as I don't have too much time to spend on working out the issue. Since it's for a personnal project that only I will use it's not too important. It would be if it where for a client project though, so eventually I will have to get around to finding out what is going on.

Thanks for your help anyway Smile
#8

[eluser]onepieceartist[/eluser]
i've got the same darned infuriating problem - did you get to the bottom of it Berik??
#9

[eluser]mlage[/eluser]
Here is a guess... but try setting write over to TRUE... perhaps to rename a file... you must write over the original?




Theme © iAndrew 2016 - Forum software by © MyBB