Last active
January 20, 2025 12:04
-
-
Save arudmin/a803d3e975662753c6745252cb785d69 to your computer and use it in GitHub Desktop.
allows to import images as URL to opencart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// catalog/model/tool/image.php | |
if (!is_file(DIR_IMAGE . $filename)) { | |
if (filter_var($filename, FILTER_VALIDATE_URL)) { | |
// generating dirname as first digit of productID (from filename) // PHP_EOL | |
preg_match_all('/_(\d{4,6})/m', basename($filename), $matches, PREG_SET_ORDER, 0); | |
$image_dir = $matches[0][1] ? $matches[0][1][0] : 'temp'; | |
$image_name = $matches[0][1] ? basename($filename) : substr(base64_encode($filename), 0, 7); | |
$image_path = 'catalog/' . $image_dir . '/' . $image_name; | |
if (!is_file(DIR_IMAGE . $image_path)) { | |
if (!is_dir(dirname(DIR_IMAGE . $image_path))){ | |
@mkdir(dirname(DIR_IMAGE . $image_path), 0700); | |
} | |
$filename = file_put_contents(DIR_IMAGE . $image_path, file_get_contents($filename)) ? $image_path : 'no_image.jpg'; | |
} else { | |
$filename = $image_path; | |
} | |
} else { | |
if (is_file(DIR_IMAGE . 'no_image.jpg')) { | |
$filename = 'no_image.jpg'; | |
} elseif (is_file(DIR_IMAGE . 'no_image.png')) { | |
$filename = 'no_image.png'; | |
} else { | |
return; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good day, does this code when site is locally hosted