I can't figure out how to do this - if there is no extension, I cannot add it to acceptable filetypes. Forum search didn't help.
Forums
How to accept uploading files WITHOUT extension?
Hi artsapiens,
Don't accept them, it's a major security risk to your site that you should not take.
Bob
Don't accept them, it's a major security risk to your site that you should not take.
Bob
The problem is that some smartphones (some older models I suppose) when trying to upload photos, slice out image extension.
Maybe there is possibility just to voluntarily ADD some extension (.jpg for example) during upload if uploading file doesn't have one?
Thanks in advance, Bob!
Maybe there is possibility just to voluntarily ADD some extension (.jpg for example) during upload if uploading file doesn't have one?
Thanks in advance, Bob!
Hi artsapiens,
You can use Custom PHP to check the files before the Upload Files action and add jpg if there is no extension set. Check the Joomla JFiles class for the code to use.
Bob
You can use Custom PHP to check the files before the Upload Files action and add jpg if there is no extension set. Check the Joomla JFiles class for the code to use.
Bob
Maybe you want to use:
getExt(string $file) : stringin your custom code to get the extension of a file name. See more at Joomla API Index
I'm trying to use jfile, but it doesn't seem to solve the problem.
The code I try:[pre]jimport('joomla.filesystem.file');
$jinput = JFactory::getApplication()->input;
$file = $jinput->files->get('file_up'); /* this is file field name */
$info = pathinfo($this->data[file_up]);
if (!$info["extension"]) {
$this->data[file_up] .= "_added_EXT.jpg";
$this->data[file_data_before_change] = $file;
$file['name'] .= "_added_EXT.jpg";
$file['type'] = "image/jpeg"; [br]$this->data[file_data_after_change] = $file;[br]}[/pre]
(the code isinside Custom Php BEFORE Validate Fields part)
and debugger output is:
Any suggestions?
The code I try:[pre]jimport('joomla.filesystem.file');
$jinput = JFactory::getApplication()->input;
$file = $jinput->files->get('file_up'); /* this is file field name */
$info = pathinfo($this->data[file_up]);
if (!$info["extension"]) {
$this->data[file_up] .= "_added_EXT.jpg";
$this->data[file_data_before_change] = $file;
$file['name'] .= "_added_EXT.jpg";
$file['type'] = "image/jpeg"; [br]$this->data[file_data_after_change] = $file;[br]}[/pre]
(the code isinside Custom Php BEFORE Validate Fields part)
and debugger output is:
...as you can see, tmp file name (including extension) is changed, and even filetype changed as well, but I still getting "File extension is not permitted" error, and file is not uploaded.
[file_up] => testfile_added_EXT.jpg
...
[file_data_before_change] => Array
(
[name] => testfile
[type] => application/octet-stream
[tmp_name] => /data02/***/tmp/phpqdevMO
[error] => 0
[size] => 594182[br] )[br][br] [file_data_after_change] => Array[br] ([br] [name] => testfile_added_EXT.jpg[br] [type] => image/jpeg[br] [tmp_name] => /data02/***/tmp/phpqdevMO[br] [error] => 0[br] [size] => 594182[br] )[br]...
Any suggestions?
in your custom code to get the extension of a file name.
You're not getting the problem. I'm trying to deal with files WITHOUT any extension.
Hi artsapiens,
I think that you need to rename the files in the PHP temporary upload folder before the CF Files Upload action
Bob
I think that you need to rename the files in the PHP temporary upload folder before the CF Files Upload action
Bob
Hi Bob, this is exactly what I'm doing, I'm operating over php temp files (see file path / tmp_name in Debugger on previous post), and it happens BEFORE CF validation and upload (see screenshot attached)
![](Screen_Shot_2019-11-24_at_17.46.13.jpg)
Hi artsapiens,
I think that your code is changing the name in the form data - but that will be overwritten by the Upload Files action - it needs to be renamed in the temporary folder so that CF loads the already renamed file.
Bob
I think that your code is changing the name in the form data - but that will be overwritten by the Upload Files action - it needs to be renamed in the temporary folder so that CF loads the already renamed file.
Bob
Hi Bob,
I experimented on localhost to be able to check what's going on in /tmp directory.
So, what I see, is the file, which is mentioned as [tmp_name] in debugger output:
never has any extension, whatever I upload - is it any file with extension or without - this temporary file has no extension, see below:
1 - file without extension:[pre] [file_data_before_change] => Array
(
[name] => [mark]tmp-img-no-ext[/mark][br] [type] => application/octet-stream[br] [tmp_name] => /Applications/MAMP/tmp/php/[strong][mark]phpbUO4CT[/mark][/strong][br] [error] => 0[br] [size] => 34357[br] )[/pre]
2 - file WITH extension:
I don't think that adding extension to this temporary file is the solution. It's not intended to have any.
I experimented on localhost to be able to check what's going on in /tmp directory.
So, what I see, is the file, which is mentioned as [tmp_name] in debugger output:
[tmp_name] => /data02/***/tmp/phpqdevMO
never has any extension, whatever I upload - is it any file with extension or without - this temporary file has no extension, see below:
1 - file without extension:[pre] [file_data_before_change] => Array
(
[name] => [mark]tmp-img-no-ext[/mark][br] [type] => application/octet-stream[br] [tmp_name] => /Applications/MAMP/tmp/php/[strong][mark]phpbUO4CT[/mark][/strong][br] [error] => 0[br] [size] => 34357[br] )[/pre]
2 - file WITH extension:
[file_data_before_change] => ArrayI opened that folder in Finder and I see these files blinking, appearing for a split second and then disappear immediately.
(
[name] => tmp-img.jpg
[type] => image/jpeg
[tmp_name] => /Applications/MAMP/tmp/php/phpD9qFqz
[error] => 0
[size] => 34357[br] )
I don't think that adding extension to this temporary file is the solution. It's not intended to have any.
ok, here is the solution that worked for me:
add php code before validation:
add php code before validation:
$info = pathinfo($this->data[file_up]); /* necessary for finding file extension*/where file_up is the name of your file field in your form.
if (!$info["extension"]) { /* if no extensin found */
$_FILES[file_up][name] .= "_added_EXT.jpg"; /* add some text to filename and .jpg extension */
}
Hi artsapiens,
Please see this FAQ which has some code written for a related problem. I think you should be able to adapt it to set an extension if there isn't one.
Bob
Please see this FAQ which has some code written for a related problem. I think you should be able to adapt it to set an extension if there isn't one.
Bob
Hi Bob,
key things there happens:
which is pretty much the same what is my code doing.
Thanks though!
key things there happens:
$name = "{$name}_{$i}.{$ext}"; $_FILES[$k]['name'] = $name;
which is pretty much the same what is my code doing.
Thanks though!
This topic is locked and no more replies can be posted.