What's up friends.
In Version 2.2 when viewing images uploaded in comment attachments, the images were displayed correctly.
Upgrade to version 2.3 and the images were no longer displayed correctly
Version 2.2
Now
Version 2.3
Then I analyzed the source code and found it in the info.php file located at: ..\modules\items\actions\info.php
ob_clean() missing;
Then I had to add it.
the code that fails says in line 121 (info.php):
-----------------------------------------------------------------------------
case 'download_attachment':
$file = attachments::parse_filename(base64_decode($_GET['file']));
//check if using file storage for feild
if(class_exists('file_storage') and isset($_GET['field']))
{
file_storage::download_file(_get::int('field'), base64_decode($_GET['file']));
}
if(is_file($file['file_path']))
{
if($file['is_image'] and isset($_GET['preview']))
{
$size = getimagesize($file['file_path']);
header("Content-type: " . $size['mime']);
header('Content-Disposition: filename="' . $file['name'] . '"');
flush();
readfile($file['file_path']);
}
elseif($file['is_pdf'] and isset($_GET['preview']))
{
header("Content-type: application/pdf");
header('Content-Disposition: filename="' . $file['name'] . '"');
flush();
readfile($file['file_path']);
}
else
{
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.$file['name']);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file['file_path']));
flush();
readfile($file['file_path']);
}
}
else
{
echo TEXT_FILE_NOT_FOUD;
}
exit();
break;
--------------------------------------------------------------------------------------
I believe that the correct thing is the following:
--------------------------------------------------------------------------------------
case 'download_attachment':
$file = attachments::parse_filename(base64_decode($_GET['file']));
//check if using file storage for feild
if(class_exists('file_storage') and isset($_GET['field']))
{
file_storage::download_file(_get::int('field'), base64_decode($_GET['file']));
}
if(is_file($file['file_path']))
{
if($file['is_image'] and isset($_GET['preview']))
{
$size = getimagesize($file['file_path']);
header("Content-type: " . $size['mime']);
header('Content-Disposition: filename="' . $file['name'] . '"');
ob_clean();
flush();
readfile($file['file_path']);
}
elseif($file['is_pdf'] and isset($_GET['preview']))
{
header("Content-type: application/pdf");
header('Content-Disposition: filename="' . $file['name'] . '"');
ob_clean();
flush();
readfile($file['file_path']);
}
else
{
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.$file['name']);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file['file_path']));
ob_clean();
flush();
readfile($file['file_path']);
}
}
else
{
echo TEXT_FILE_NOT_FOUD;
}
exit();
break;
------------------------------------------------------------------
With this I did not have any errors and images are already displayed well.
I look forward to your comments Sergey
Regards
atta. Danyell
Error to preview uploaded files (images) in Versión 2.3
-
- Posts: 24
- Joined: 28 Jun 2017, 01:17
- Name: Danyell
- Location: Ciudad de México
- Company Name: Personal
- support
- Site Admin
- Posts: 6231
- Joined: 19 Oct 2014, 18:22
- Name: Sergey Kharchishin
- Location: Russia, Evpatoriya
Re: Error to preview uploaded files (images) in Versión 2.3
According to documentation http://us1.php.net/manual/en/function.ob-clean.php
Rukovoditel does not use ob_start that is why I have removed ob_clean.The output buffer must be started by ob_start() with PHP_OUTPUT_HANDLER_CLEANABLE flag. Otherwise ob_clean() will not work.