Welcome Guest, Not a member yet? Register   Sign In
upload max filename less than 32 does not work
#1

I'm trying to set up the upload library configuration as follows:


PHP Code:
$attachmentEXT = array('doc''docx''jpg''jpeg''pdf''png''rar''zip');
$this->load->library('upload', array(
 
'allowed_types' => implode('|'$attachmentEXT),
 
'encrypt_name' => TRUE,
 
'max_filename' => 27,
 
'max_size' => 1024,
 
'upload_path' => upload_dir()
)); 
I set max file name 27, because in the column I select VARCHAR (32)
27 characters for encrypted file name
5 characters for the file extension.

But I get when uploading DOCX, file name length is 37.
32 characters for encrypted file name
5 characters for the file extension.

What's wrong with the above configuration?

Attached Files Thumbnail(s)
   
Reply
#2

I believe that 'max_filename' only pertains to the name of the selected file and has nothing to do with the encrypted name. Perhaps it should, but it does not.
Reply
#3

(This post was last modified: 01-30-2018, 04:47 PM by DorkSQLi.)

(01-30-2018, 04:27 PM)daveĀ friend Wrote: I believe that 'max_filename' only pertains to the name of the selected file and has nothing to do with the encrypted name. Perhaps it should, but it does not.

For now I assume that `max_filename` only calculates file names excluding extensions.
Then there I set `max_filename` with 27 characters and the length of the extension is 5. so the total length is 32 characters.
But the fact that I get 32 characters for the length of file name & length of extension is 5.
Reply
#4

(This post was last modified: 01-31-2018, 03:07 AM by dave friend.)

`max_filename` length includes the extension and the (dot).

The class method that limits the file name length is cleverly called limit_filename_length(). It accepts two arguments $filename, $length and returns a string.

When I run this code

PHP Code:
$this->load->library('upload');
$fname 'some longish filename.asdfg';
$x $this->upload->limit_filename_length($fname15);
echo 
$x

The output is
Code:
some long.asdfg

Which is exactly 15 characters including the dot.

The code that runs if 'encrypt_name' === TRUE doesn't happen until after limit_filename_length() is called.The encrypt name value is derived from md5(uniqid(mt_rand())) .
md5() returns a 32-character hexadecimal number. So the file name length is for sure more than the 15 characters we specified earlier. It's going to be exactly 32 characters plus the length of the file extension and the dot - so a length of 38 with our ".asdfg" type file.

The moral of the story is that if you use 'encrypt_name' => TRUE then 'max_filename' has no effect.
Reply
#5

(01-31-2018, 02:41 AM)daveĀ friend Wrote: `max_filename` length includes the extension and the (dot).

The class method that limits the file name length is cleverly called limit_filename_length(). It accepts two arguments $filename, $length and returns a string.

When I run this code

PHP Code:
$this->load->library('upload');
$fname 'some longish filename.asdfg';
$x $this->upload->limit_filename_length($fname15);
echo 
$x

The output is
Code:
some long.asdfg

Which is exactly 15 characters including the dot.

The code that runs if 'encrypt_name' === TRUE doesn't happen until after limit_filename_length() is called.The encrypt name value is derived from md5(uniqid(mt_rand())) .
md5() returns a 32-character hexadecimal number. So the file name length is for sure more than the 15 characters we specified earlier. It's going to be exactly 32 characters plus the length of the file extension and the dot - so a length of 38 with our ".asdfg" type file.

The moral of the story is that if you use 'encrypt_name' => TRUE then 'max_filename' has no effect.

Thanks for the explanation, I think when `encrypt_name` is given TRUE then` max_filename` will work

Perhaps the documentation section needs to be updated as described above, so that a layman like me is easy to understand Big Grin
Reply




Theme © iAndrew 2016 - Forum software by © MyBB