Welcome Guest, Not a member yet? Register   Sign In
$config['file_name'] malfunction
#1

[eluser]Maglok[/eluser]
I've worked with the upload class before.

I have some code, where it uploads just fine. Due to the nature of the image though, I want the name to be the username (which is unique).

Thus I tried to use $config['file_name'] = $username

This doesn't seem to do anything. Some searching on the forum gave me a few threads where the problem was never really anwsered.

My config:

Code:
$config['upload_path'] = base_url() . 'uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']    = '100';
        $config['max_width']  = '1000';
        $config['max_height']  = '1000';
        $config['file_name'] = $medewerker->solisid;

I have also figgled a bit with the $config['overwrite'], to no avail.
#2

[eluser]smilie[/eluser]
I am guessing (from CI userguide):

If set CodeIgniter will rename the uploaded file to this name. The extension provided in the file name must also be an allowed file type.

Therefore:
Code:
$config['file_name'] = $medewerker->solisid.".jpg";
should work.
However, you can never know what extension should it be - before file is uploaded...?

This is not tested, just stumbled upon it in the Userguide.

Regards,
Smilie
#3

[eluser]Maglok[/eluser]
Yeah I have read the userguide. I have tried with extension jpg and then upload a jpg before as well. No dice.

The userguide claims at one point that you need the extension. Forum people claim at one point that you don't. So tried both.

Edit:

Quote:While fixing this bug, we took the opportunity to make an improvement to the Upload class’s ability to allow a file name override. Previously, you needed to do a little dance in your controller to remove the extension from the file name if you were starting from user input; neither could you override the file extension. Now when using the “file_name” config override, you will supply the full file name, including the extension, truly overriding the file name provided by the client user agent.

Ok 1.7.2 seems to have changed this. Still, I tried with extension. Also this is a 1.7.2 I am using.

And to boot: How could I predict what filename extension it is going to be?
#4

[eluser]Maglok[/eluser]
Well work had to continue so I worked around it with this quickfix:

Code:
rename($medewerker['foto']['full_path'], $medewerker['foto']['file_path'] . $data['user'] . $medewerker['foto']['file_ext']);

Basically renaming after it is uploaded. Shame the file_name one didn't work. Has anyone else have it working in the latest version I wonder?




Theme © iAndrew 2016 - Forum software by © MyBB