39 lines
1.4 KiB
PHP
39 lines
1.4 KiB
PHP
<?php
|
|
|
|
require(dirname(__FILE__).'/../../config/config.inc.php');
|
|
require_once _PS_MODULE_DIR_ . '/configurator/classes/Config.php';
|
|
$config_id = $_POST['config_id'];
|
|
if($config_id) {
|
|
if (isset($_FILES['file']) && $_FILES['file']['size'] > 0)
|
|
{
|
|
$config = new \Config($config_id);
|
|
$img_pub_path = _PS_IMG_DIR_."configurator/";
|
|
$image = glob($img_pub_path . $config_id . '.{jpg,jpeg,png}', GLOB_BRACE);
|
|
|
|
if (is_array($image))
|
|
$image = reset($image);
|
|
|
|
$image_name = pathinfo($image, PATHINFO_BASENAME);
|
|
$image = $img_pub_path . $image_name;
|
|
if (!is_dir($image) && file_exists($image))
|
|
{
|
|
if (!unlink($image))
|
|
return false;
|
|
}
|
|
|
|
$filename = $_FILES['file']['name'];
|
|
$tmpname = $_FILES['file']['tmp_name'];
|
|
$extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
|
|
$upload_path = $img_pub_path . $config->id.'_'. $config->id_page . '.' . $extension;
|
|
|
|
$img_pub_path_uri = _PS_IMG_."configurator/";
|
|
if(move_uploaded_file($tmpname, $upload_path))
|
|
{
|
|
@chmod($upload_path, 0664);
|
|
$config->image = Media::getMediaPath($img_pub_path_uri.$config->id.'_'. $config->id_page . '.' . $extension);
|
|
$config->update();
|
|
}
|
|
@unlink($img_pub_path . $config->id.'_'. $config->id_page . '.webp');
|
|
die($config->image);
|
|
}
|
|
} |