ДОброго времени суток всем. Кто может сказать, как скрыть адреса картинок реальные в опенкарт.
Есть каталог, в нём картинки грузятся иногда с других серверов (ничего криминального, для экономии места на хостинге картинки не загружаются на хост) Хлтелось бы, чтобы юзеры не видели их реальный адрес...
Ocstore 2.3
Костыль воткнул:
В представлении:
<img src="imageload.php?product_id=<?php echo $product_id; ?>">
В imageload.php
<?php
$product_id=$_GET['product_id'];
$product_image_id=$_GET['product_image_id'];
function getProductImage($product_id) {
$mysqli = new mysqli(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
$image=$mysqli->query("SELECT image FROM " . DB_PREFIX . "product WHERE product_id = '" . (int)$product_id . "'" )->fetch_object()->image;
$mysqli->close();
return $image;
}
function getProductImages($product_image_id) {
$mysqli = new mysqli(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
$images=$mysqli->query("SELECT image FROM " . DB_PREFIX . "product_image WHERE product_image_id = '" . (int)$product_image_id . "' ORDER BY sort_order ASC" );
//$imagess=$images->fetch_array();
$mysqli->close();
return $images;
}
//$result = mysqli_query( $link, "SELECT image FROM " . DB_PREFIX . "product WHERE product_id = '" . (int)$product_id . "'" );
//$urlImg = $mysqli->query("SELECT image FROM " . DB_PREFIX . "product WHERE product_id = '" . (int)$product_id . "'");
//$urlImg = $result->row['product_id'];
//$urlImg = getProductImages($product_id);
//print $urlImg; //output value
//$row = $results->fetch_array()
//echo $urlImg;
// print_r ($result);
//"SELECT image FROM " . DB_PREFIX . "product_image WHERE product_image_id = '" . (int)$product_image_id . "' ORDER BY sort_order ASC"
function my_url_encode($s){
$s= strtr ($s, array (" "=> "%20", "а"=>"%D0%B0", "А"=>"%D0%90","б"=>"%D0%B1", "Б"=>"%D0%91", "в"=>"%D0%B2", "В"=>"%D0%92", "г"=>"%D0%B3", "Г"=>"%D0%93", "д"=>"%D0%B4", "Д"=>"%D0%94", "е"=>"%D0%B5", "Е"=>"%D0%95", "ё"=>"%D1%91", "Ё"=>"%D0%81", "ж"=>"%D0%B6", "Ж"=>"%D0%96", "з"=>"%D0%B7", "З"=>"%D0%97", "и"=>"%D0%B8", "И"=>"%D0%98", "й"=>"%D0%B9", "Й"=>"%D0%99", "к"=>"%D0%BA", "К"=>"%D0%9A", "л"=>"%D0%BB", "Л"=>"%D0%9B", "м"=>"%D0%BC", "М"=>"%D0%9C", "н"=>"%D0%BD", "Н"=>"%D0%9D", "о"=>"%D0%BE", "О"=>"%D0%9E", "п"=>"%D0%BF", "П"=>"%D0%9F", "р"=>"%D1%80", "Р"=>"%D0%A0", "с"=>"%D1%81", "С"=>"%D0%A1", "т"=>"%D1%82", "Т"=>"%D0%A2", "у"=>"%D1%83", "У"=>"%D0%A3", "ф"=>"%D1%84", "Ф"=>"%D0%A4", "х"=>"%D1%85", "Х"=>"%D0%A5", "ц"=>"%D1%86", "Ц"=>"%D0%A6", "ч"=>"%D1%87", "Ч"=>"%D0%A7", "ш"=>"%D1%88", "Ш"=>"%D0%A8", "щ"=>"%D1%89", "Щ"=>"%D0%A9", "ъ"=>"%D1%8A", "Ъ"=>"%D0%AA", "ы"=>"%D1%8B", "Ы"=>"%D0%AB", "ь"=>"%D1%8C", "Ь"=>"%D0%AC", "э"=>"%D1%8D", "Э"=>"%D0%AD", "ю"=>"%D1%8E", "Ю"=>"%D0%AE", "я"=>"%D1%8F", "Я"=>"%D0%AF"));
return $s;
}
if (isset($_GET['product_image_id'])){
$urlImgs=getProductImages($product_image_id);
//print_r($urlImgs->fetch_array());
$imgrow = $urlImgs->fetch_array();
header('Location: '.$imgrow["image"]);
} else {
$urlImg = getProductImage($product_id);
if ($urlImg == null) {
$urlImg="/image/placeholder.png";
header('Location: '.$urlImg);
} else {
$urlImg = getProductImage($product_id);
$urlImg2 = my_url_encode($urlImg);
$Headers = @get_headers($urlImg2);
// проверяем ли ответ от сервера с кодом 200 - ОК
if(preg_match("|200|", $Headers[0]) or preg_match("|301|", $Headers[0]) ) { // - немного дольше :)
//if(strpos('200', $Headers[0])) {
header('Location: '.$urlImg);
} else {
$urlImg="/image/placeholder.png";
header('Location: '.$urlImg);
}
}
}
exit();
?>
Но проблема в том, что если нажать сохранить как на картинку или напрямую в адресной строке вбить Imageload.php?product_id=123 то естественно картинка открывается и видно адрес ресурса. Хочется сделать так, чтобы скрипт срабатывал только извне...
Разнес по модели и контроллеру код
Выдает
PHP Fatal error: Class 'Controller' not found in .../productimg.php on line 2
Код контроллера:
<?php
class ControllerProductProductimg extends Controller {
//private $error = array();
public function index() {
$this->load->model('catalog/productimg');
$this->request->get['product_id'];
$this->request->get['product_image_id'];
function my_url_encode($s){
$s= strtr ($s, array (" "=> "%20", "а"=>"%D0%B0", "А"=>"%D0%90","б"=>"%D0%B1", "Б"=>"%D0%91", "в"=>"%D0%B2", "В"=>"%D0%92", "г"=>"%D0%B3", "Г"=>"%D0%93", "д"=>"%D0%B4", "Д"=>"%D0%94", "е"=>"%D0%B5", "Е"=>"%D0%95", "ё"=>"%D1%91", "Ё"=>"%D0%81", "ж"=>"%D0%B6", "Ж"=>"%D0%96", "з"=>"%D0%B7", "З"=>"%D0%97", "и"=>"%D0%B8", "И"=>"%D0%98", "й"=>"%D0%B9", "Й"=>"%D0%99", "к"=>"%D0%BA", "К"=>"%D0%9A", "л"=>"%D0%BB", "Л"=>"%D0%9B", "м"=>"%D0%BC", "М"=>"%D0%9C", "н"=>"%D0%BD", "Н"=>"%D0%9D", "о"=>"%D0%BE", "О"=>"%D0%9E", "п"=>"%D0%BF", "П"=>"%D0%9F", "р"=>"%D1%80", "Р"=>"%D0%A0", "с"=>"%D1%81", "С"=>"%D0%A1", "т"=>"%D1%82", "Т"=>"%D0%A2", "у"=>"%D1%83", "У"=>"%D0%A3", "ф"=>"%D1%84", "Ф"=>"%D0%A4", "х"=>"%D1%85", "Х"=>"%D0%A5", "ц"=>"%D1%86", "Ц"=>"%D0%A6", "ч"=>"%D1%87", "Ч"=>"%D0%A7", "ш"=>"%D1%88", "Ш"=>"%D0%A8", "щ"=>"%D1%89", "Щ"=>"%D0%A9", "ъ"=>"%D1%8A", "Ъ"=>"%D0%AA", "ы"=>"%D1%8B", "Ы"=>"%D0%AB", "ь"=>"%D1%8C", "Ь"=>"%D0%AC", "э"=>"%D1%8D", "Э"=>"%D0%AD", "ю"=>"%D1%8E", "Ю"=>"%D0%AE", "я"=>"%D1%8F", "Я"=>"%D0%AF"));
return $s;
}
if (isset($this->request->get['product_image_id'])){
$urlImgs=$this->model_catalog_productimg->getProductImages($product_image_id);
//print_r($urlImgs->fetch_array());
$imgrow = $urlImgs->fetch_array();
header('Location: '.$imgrow["image"]);
} else {
$urlImg = $this->model_catalog_productimg->getProductImage($product_id);
if ($urlImg == null) {
$urlImg="/image/placeholder.png";
header('Location: '.$urlImg);
} else {
$urlImg = $this->model_catalog_productimg->getProductImage($product_id);
$urlImg2 = my_url_encode($urlImg);
$Headers = @get_headers($urlImg2);
// проверяем ли ответ от сервера с кодом 200 - ОК
if(preg_match("|200|", $Headers[0]) or preg_match("|301|", $Headers[0]) ) { // - немного дольше :)
//if(strpos('200', $Headers[0])) {
header('Location: '.$urlImg);
} else {
$urlImg="/image/placeholder.png";
header('Location: '.$urlImg);
}
}
}
}
}
Может есть у кого мысли?