Flatpress 1.2.1 and Uploader

This is the right place to report general bugs, make suggestions or ask for help.
Post Reply
laborix
Posts: 118
Joined: Sat Feb 16, 2019 3:51 pm

Flatpress 1.2.1 and Uploader

Post by laborix » Sat Jun 18, 2022 3:37 pm

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.

User avatar
Arvid
FlatPress Coder
Posts: 558
Joined: Sat Jan 26, 2019 7:40 pm
Contact:

Re: Flatpress 1.2.1 and Uploader

Post by Arvid » Sat Jun 18, 2022 7:39 pm

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

laborix
Posts: 118
Joined: Sat Feb 16, 2019 3:51 pm

Re: Flatpress 1.2.1 and Uploader

Post by laborix » Sun Jun 19, 2022 9:20 am

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 :)

User avatar
Arvid
FlatPress Coder
Posts: 558
Joined: Sat Jan 26, 2019 7:40 pm
Contact:

Re: Flatpress 1.2.1 and Uploader

Post by Arvid » Sun Jun 19, 2022 10:43 am

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 :)

laborix
Posts: 118
Joined: Sat Feb 16, 2019 3:51 pm

Re: Flatpress 1.2.1 and Uploader

Post by laborix » Sun Jun 19, 2022 4:17 pm

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.

User avatar
Arvid
FlatPress Coder
Posts: 558
Joined: Sat Jan 26, 2019 7:40 pm
Contact:

Re: Flatpress 1.2.1 and Uploader

Post by Arvid » Sat Jul 09, 2022 12:32 pm

Was able to reproduce it that way, thanks!

Post Reply

Who is online

Users browsing this forum: No registered users and 37 guests