Is File Upload class creates unique file name when encrypt_name set true? |
Is File Uploading class in code ignter creates unique file name when encrypt_name set true?
PHP Code: $config['upload_path'] = $abs_path;
It's in the User's Guide.
encrypt_name If set to TRUE the file name will be converted to a random encrypted string. This can be useful if you would like the file saved with a name that can not be discerned by the person uploading it. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(10-30-2018, 03:07 AM)InsiteFX Wrote: It's in the User's Guide.Thanks for the quick reply. I already read the guide. My question is, whether it will be a unique name. Because, I am storing all user uploads in a single folder, hence it should not be overwritten at any time. Also, I could not able to find a way to prefix a unique id to the random filename. If I manually set a unique file name, unable to determine the original file's extension.
encrypt_name does not guarantee a unique file name. That said, the chance of a name collision is incredibly small. But a small chance is not the same as no chance.
You might be interested to know that do_upload() calls set_filename() and set_filename() will append a number to the end of the filename to avoid overwriting a pre-existing file. This happens for any file upload encrypted name or not.
Personally I'm using a UUID version 4 generator for my file names and all ID (instead of auto increment).
PHP Code: if ( ! function_exists('UUIDv4')) https://en.wikipedia.org/wiki/Universall...Collisions
(10-30-2018, 09:41 AM)dave friend Wrote: You might be interested to know that do_upload() calls set_filename() and set_filename() will append a number to the end of the filename to avoid overwriting a pre-existing file. This happens for any file upload encrypted name or not.This is the function i want.
Thanks @jreklund & @Dave friend, I finally ended with prefixing auto-increament id along with uuid to the uploaded file name. I worried about setting the original file's extension with filename, but CodeIgniter automatically preserves the original file's extension even I didn't mention it in $config['file_name'] parameter.
You need a .htaccess file on your root folder
like below code RewriteEngine On RewriteCond %{REQUEST_URI} ^/system.* RewriteRule ^(.*)$ index.php?/$1 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)$ index.php?/$1 [L] |
Welcome Guest, Not a member yet? Register Sign In |