I’ve searched for some code snippets to upload PDF files (like tech specs for certain products) in the product description fckeditor window, but without success, so I edited the code myself and here’s it if you need to do something similar! I know there are better ways of doing it (not to mention using MIME instead of plain text for the extension), but I had no time to check them.
So, here’s the code of the only file I’ve modified, /admin/controller/common/filemanager.php
I’ve also uploaded an icon for the editor called “pdf.jpg” in the image directory.
/
Around line 84, add the desidered file extension[s], “pdf” in this example: change from this…
$files = glob(rtrim($directory, '/') . '/*.{jpg,jpeg,png,gif}', GLOB_BRACE);
…to this:
$files = glob(rtrim($directory, '/') . '/*.{jpg,jpeg,png,gif,pdf}', GLOB_BRACE);
Next, go down; around line 108 you should find:
$json[] = array(
'file' => substr($file, strlen(DIR_IMAGE . 'data/')),
'filename' => basename($file),
'size' => round(substr($size, 0, strpos($size, '.') + 4), 2) . $suffix[$i],
'thumb' => image_resize(substr($file, strlen(DIR_IMAGE)), 100, 100)
alter it this way:
$path_info = pathinfo($file);
if ($path_info['extension'] != "pdf")
{ // image files
$json[] = array(
'file' => substr($file, strlen(DIR_IMAGE . 'data/')),
'filename' => basename($file),
'size' => round(substr($size, 0, strpos($size, '.') + 4), 2) . $suffix[$i],
'thumb' => image_resize(substr($file, strlen(DIR_IMAGE)), 100, 100)
);
} else {
// PDF files
$json[] = array(
'file' => substr($file, strlen(DIR_IMAGE . 'data/')),
'filename' => basename($file),
'size' => round(substr($size, 0, strpos($size, '.') + 4), 2) . $suffix[$i],
'thumb' => HTTP_IMAGE."pdf.jpg"
);
}
Let’s add the MIME Filetype: around line 408, you should have:
$allowed = array(
'image/jpeg',
'image/pjpeg',
'image/png',
'image/x-png',
'image/gif',
'application/x-shockwave-flash'
);
Add the desidered mime filetype[s] in the array:
$allowed = array(
'image/jpeg',
'image/pjpeg',
'image/png',
'image/x-png',
'image/gif',
'application/x-shockwave-flash',
'application/pdf'
);
Last, but not least, go around line 423:
$allowed = array(
'.jpg',
'.jpeg',
'.gif',
'.png',
'.flv'
);
add the extension (dot included):
$allowed = array(
'.jpg',
'.jpeg',
'.gif',
'.png',
'.flv',
'.pdf'
);
Obviously, this junky code can be extended for use with multiple filetypes; just add “elseif” statements or convert it to a try-catch.
Now you should be able to upload PDF files (or whatever kind of file you’ve added) in your OpenCart!
Thanks NAZZA from opencart forum.
