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 1 commit
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
33 changes: 33 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,37 @@ 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);
else
$mimeType = $this->_mime_content_type($filename);

if($mimeType == $mimeTypeAllowed)
return true;
else
return false;
}

/**
* mime_content_type could be undefined
* @see Uncaught Error: Call to undefined function mime_content_type()
* @param $filename
* @return bool|string
*/
private function _mime_content_type($filename) {
$result = new finfo();

if (is_resource($result) === true) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This returns false because finfo is a class object, not a resource.

return $result->file($filename, FILEINFO_MIME_TYPE);
}
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