Skip to content

Instantly share code, notes, and snippets.

@Shagshag
Created December 15, 2020 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shagshag/9b7ca766e6a855ba17d8af9c71412076 to your computer and use it in GitHub Desktop.
Save Shagshag/9b7ca766e6a855ba17d8af9c71412076 to your computer and use it in GitHub Desktop.
Allow product image with ID > 9 999 999 in PrestaShop
<?php
class PageNotFoundController extends PageNotFoundControllerCore
{
public function initContent()
{
list($filename) = explode('?', substr($_SERVER['REQUEST_URI'], 6));
if (preg_match('/([0-9]+)(\-[_a-zA-Z0-9-]*)?\/.*\.jpg/', $filename, $matches)) {
$path = _PS_ROOT_DIR_.'/img/p/'.implode('/', str_split($matches[1], 1)).'/'.$matches[1].$matches[2].'.jpg';
if (file_exists($path)) {
header('Content-Type: '.mime_content_type($path)?:'image/jpg');
readfile($path);
die();
} else {
header('HTTP/1.1 404 Not Found');
header('Status: 404 Not Found');
header('Content-Type: image/gif');
readfile(_PS_ROOT_DIR_.'/img/404.gif');
die();
}
}
return parent::initContent();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment