Page 1 of 1

Flatpress 1.2.1 and Uploader

Posted: Sat Jun 18, 2022 3:37 pm
by laborix
With Flatpress 1.2.1 the following PHP warning can occur when uploading files:
PHP Warning:
Undefined array key "uploaded_files" in .../fp-content/cache/e93fccb09cf8b04111b9595da102f3f4^%%9D^9D6^9D6FBCCD%%default.php on line 21
This error occurs when non-permitted files (Flatpress Uploader Blacklist) or incorrect Mime_Types of files are detected when uploading to Flatpress. There are two possible solutions to eliminate this uploader warning.

Solution 1:
file: /admin/panels/uploader/admin.uploader.php

Remove the complete query in line 206:

Code: Select all

if (($mime == "text/x-php") || ($mime == "text/html")) {
  $this->smarty->assign('success', $success ? 1 : -1);
  sess_add('admin_uploader_files', $uploaded_files);
  return -1;
} 
Solution 2:
file: /admin/panels/uploader/admin.uploader.php

Replace the complete query in line 206 with the following code:

Code: Select all

if (($mime == "text/x-php") || ($mime == "text/html")) {
  $this->smarty->assign('success', $success ? 1 : -1);
  $notuploaded = "The file " . $name . " is not uploaded!";
  $this->smarty->assign('uploaded_files', $notuploaded);
  sess_add('admin_uploader_files', $uploaded_files);
  return -1;
} 
With Solution 2, the above PHP warning is resolved, but the situation with incorrectly recognised Mime_Types remains.

Re: Flatpress 1.2.1 and Uploader

Posted: Sat Jun 18, 2022 7:39 pm
by Arvid
Hi,

thank you very much for your tests and the suggested fixes. I have opened issue 114 and will look into it :)

All the best,
Arvid

Re: Flatpress 1.2.1 and Uploader

Posted: Sun Jun 19, 2022 9:20 am
by laborix
Arvid wrote: Sat Jun 18, 2022 7:39 pm... I have opened issue 114 and will look into it :) ...
the current reason for this posting was the PHP error message with "Undefined array key".
This problem is solved quite simply with this code line:

Code: Select all

...
$this->smarty->assign('uploaded_files', 'Some text');
...
the Variable "uploaded_files" is now no longer "Undefined" :D

The trigger, i.e. the faulty Mime_Type evaluation, is a completely different story. According to various forum posts, you can use a query of the Mime_Type and others are of the opinion that this is nonsense.
In my case, a plain text file was recognised as "text/html", both with

Code: Select all

...
$mime = finfo_file($finfo, $tmp_name);
...
as well as with in some forums as recommended method the second PHP Mime_Type function

Code: Select all

...
$mime = mime_content_type($tmp_name);
...
After testing with several different files, I decided to at least remove the PHP warning.

I leave the topic of Mime_Type open on purpose, it can also be discussed here.

Have a nice day :)

Re: Flatpress 1.2.1 and Uploader

Posted: Sun Jun 19, 2022 10:43 am
by Arvid
laborix wrote: Sun Jun 19, 2022 9:20 am This problem is solved quite simply with this code line:

Code: Select all

...
$this->smarty->assign('uploaded_files', 'Some text');
...
Done, that was simple indeed :)

laborix wrote: Sun Jun 19, 2022 9:20 amThe trigger, i.e. the faulty Mime_Type evaluation, is a completely different story.
I don't know how to reproduce this error yet. Do you have files that trigger that error?

laborix wrote: Sun Jun 19, 2022 9:20 am Have a nice day :)
You too :)

Re: Flatpress 1.2.1 and Uploader

Posted: Sun Jun 19, 2022 4:17 pm
by laborix
Arvid wrote: Sun Jun 19, 2022 10:43 am... I don't know how to reproduce this error yet. Do you have files that trigger that error? ...
Mime_Type test, rename a .html file to .txt, not edit/save, only renamethe file extension.