如何在 opencart 2 中为图像使用子域?
How to use a subdomain for images in opencart 2?
这是我的配置文件。我已更改图像子域,但图像未加载。
<?php
// HTTP
define('HTTP_SERVER', 'http://www.Yek.com/');
define('HTTP_IMAGE', 'http://img.Yek.com/');
// HTTPS
define('HTTPS_SERVER', 'https://www.Yek.com/');
define('HTTPS_IMAGE', 'https://img.Yek.com/');
// DIR
define('DIR_APPLICATION', '/home/Yek/public_html/catalog/');
define('DIR_SYSTEM', '/home/Yek/public_html/system/');
define('DIR_DATABASE', '/home/Yek/public_html/system/database/');
define('DIR_LANGUAGE', '/home/Yek/public_html/catalog/language/');
define('DIR_TEMPLATE', '/home/Yek/public_html/catalog/view/theme/');
define('DIR_CONFIG', '/home/Yek/public_html/system/config/');
//define('DIR_IMAGE', '/home/Yek/public_html/image/');//defult For Images/catlog on main host
define('DIR_IMAGE', '/home/Yek/public_html/img/image/'); // image/catalog in download host
define('DIR_CACHE', '/home/Yek/public_html/system/cache/');
define('DIR_DOWNLOAD', '/home/Yek/public_html/system/download/');
define('DIR_LOGS', '/home/Yek/public_html/system/logs/');
define('DIR_UPLOAD', '/home/Yek/public_html/system/upload/');
define('DIR_MODIFICATION', '/home/Yek/public_html/system/modification/');
// DB
....
?>
这是我的image.php。为我编辑?
不知道在哪里编辑这段代码...................................... ..................................................... ..................................................... ..................................................... ..................................................... .....................
<?php
class ModelToolImage extends Model {
public function resize($filename, $width, $height) {
if (!is_file(DIR_IMAGE . $filename)) {
return;
}
$extension = pathinfo($filename, PATHINFO_EXTENSION);
$old_image = $filename;
$new_image = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension;
if (!is_file(DIR_IMAGE . $new_image) || (filectime(DIR_IMAGE . $old_image) > filectime(DIR_IMAGE . $new_image))) {
$path = '';
$directories = explode('/', dirname(str_replace('../', '', $new_image)));
foreach ($directories as $directory) {
$path = $path . '/' . $directory;
if (!is_dir(DIR_IMAGE . $path)) {
@mkdir(DIR_IMAGE . $path, 0777);
}
}
list($width_orig, $height_orig) = getimagesize(DIR_IMAGE . $old_image);
if ($width_orig != $width || $height_orig != $height) {
$image = new Image(DIR_IMAGE . $old_image);
$image->resize($width, $height);
$image->save(DIR_IMAGE . $new_image);
} else {
copy(DIR_IMAGE . $old_image, DIR_IMAGE . $new_image);
}
}
if ($this->request->server['HTTPS']) {
return $this->config->get('config_ssl') . 'image/' . $new_image;
} else {
return $this->config->get('config_url') . 'image/' . $new_image;
}
}
}
将您的子域指向您的图片目录
在您的主机控制面板中添加子域时,您必须将其指向您的图像目录。如果您无权访问控制面板,则必须询问您的管理员。
/catalog/model/tool/image.php
发现 $this->config->get('config_url')
并改变
protected function getImageUrl($new_image) {
$parts = explode('/', $new_image);
$new_url = implode('/', array_map('rawurlencode', $parts));
if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1'))) {
return $this->config->get('config_ssl') . 'image/' . $new_url;
}
else {
return $this->config->get('config_url') . 'image/' . $new_url;
}
}
这是我的配置文件。我已更改图像子域,但图像未加载。
<?php
// HTTP
define('HTTP_SERVER', 'http://www.Yek.com/');
define('HTTP_IMAGE', 'http://img.Yek.com/');
// HTTPS
define('HTTPS_SERVER', 'https://www.Yek.com/');
define('HTTPS_IMAGE', 'https://img.Yek.com/');
// DIR
define('DIR_APPLICATION', '/home/Yek/public_html/catalog/');
define('DIR_SYSTEM', '/home/Yek/public_html/system/');
define('DIR_DATABASE', '/home/Yek/public_html/system/database/');
define('DIR_LANGUAGE', '/home/Yek/public_html/catalog/language/');
define('DIR_TEMPLATE', '/home/Yek/public_html/catalog/view/theme/');
define('DIR_CONFIG', '/home/Yek/public_html/system/config/');
//define('DIR_IMAGE', '/home/Yek/public_html/image/');//defult For Images/catlog on main host
define('DIR_IMAGE', '/home/Yek/public_html/img/image/'); // image/catalog in download host
define('DIR_CACHE', '/home/Yek/public_html/system/cache/');
define('DIR_DOWNLOAD', '/home/Yek/public_html/system/download/');
define('DIR_LOGS', '/home/Yek/public_html/system/logs/');
define('DIR_UPLOAD', '/home/Yek/public_html/system/upload/');
define('DIR_MODIFICATION', '/home/Yek/public_html/system/modification/');
// DB
....
?>
这是我的image.php。为我编辑? 不知道在哪里编辑这段代码...................................... ..................................................... ..................................................... ..................................................... ..................................................... .....................
<?php
class ModelToolImage extends Model {
public function resize($filename, $width, $height) {
if (!is_file(DIR_IMAGE . $filename)) {
return;
}
$extension = pathinfo($filename, PATHINFO_EXTENSION);
$old_image = $filename;
$new_image = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension;
if (!is_file(DIR_IMAGE . $new_image) || (filectime(DIR_IMAGE . $old_image) > filectime(DIR_IMAGE . $new_image))) {
$path = '';
$directories = explode('/', dirname(str_replace('../', '', $new_image)));
foreach ($directories as $directory) {
$path = $path . '/' . $directory;
if (!is_dir(DIR_IMAGE . $path)) {
@mkdir(DIR_IMAGE . $path, 0777);
}
}
list($width_orig, $height_orig) = getimagesize(DIR_IMAGE . $old_image);
if ($width_orig != $width || $height_orig != $height) {
$image = new Image(DIR_IMAGE . $old_image);
$image->resize($width, $height);
$image->save(DIR_IMAGE . $new_image);
} else {
copy(DIR_IMAGE . $old_image, DIR_IMAGE . $new_image);
}
}
if ($this->request->server['HTTPS']) {
return $this->config->get('config_ssl') . 'image/' . $new_image;
} else {
return $this->config->get('config_url') . 'image/' . $new_image;
}
}
}
将您的子域指向您的图片目录
在您的主机控制面板中添加子域时,您必须将其指向您的图像目录。如果您无权访问控制面板,则必须询问您的管理员。
/catalog/model/tool/image.php 发现 $this->config->get('config_url') 并改变
protected function getImageUrl($new_image) {
$parts = explode('/', $new_image);
$new_url = implode('/', array_map('rawurlencode', $parts));
if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1'))) {
return $this->config->get('config_ssl') . 'image/' . $new_url;
}
else {
return $this->config->get('config_url') . 'image/' . $new_url;
}
}