Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Uncaught Error: Call to undefined function mime_content_type() #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions app/code/community/Ash/PdfUploadAfterSupee9767/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,30 @@ public function isEnabled()
}
return false;
}

/**
* is PDF file
* @param $filename
* @return bool
*/
public function isAllowed($filename){
$mimeTypeAllowed = 'application/pdf';
if(function_exists('mime_content_type')) {
$mimeType = mime_content_type($filename);
}
elseif(function_exists("finfo_open")) {
$finfo = finfo_open(FILEINFO_MIME);
$mimeType = finfo_file($finfo, $filename);
}
else{
$mimeType = '';
}

if(strpos($mimeType, $mimeTypeAllowed) !== false) {
return true;
}
else {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class Ash_PdfUploadAfterSupee9767_Model_Rewrite_Cms_Wysiwyg_Images_Storage exten
public function resizeFile($source, $keepRation = true)
{
$isEnabled = Mage::helper('ash_pdfuploadaftersupee9767')->isEnabled();
$isAllowed = Mage::helper('ash_pdfuploadaftersupee9767')->isAllowed($source);

$mimeType = mime_content_type($source);
if ($isEnabled && $mimeType == 'application/pdf') {
if ($isEnabled && $isAllowed) {
return false;
} else {
return parent::resizeFile($source, $keepRation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ class Ash_PdfUploadAfterSupee9767_Model_Rewrite_Core_File_Validator_Image extend
public function validate($filePath)
{
$isEnabled = Mage::helper('ash_pdfuploadaftersupee9767')->isEnabled();
$isAllowed = Mage::helper('ash_pdfuploadaftersupee9767')->isAllowed($filePath);

if ($isEnabled && mime_content_type($filePath) == 'application/pdf') {
if ($isEnabled && $isAllowed) {
return null;
} else {
return parent::validate($filePath);
Expand Down