
Only Tested with X-Cart 4.0.18. (and only applies if you use File System Images Location).
Tired of writing in forced changes to func_get_thumbnail_url() so that the string manipulations would fire off the if condition to return the proper file instead of using images.php. This ALWAYS seems to happen when at any time the full local path (ie. /home/user/public_html/xcart/) changed in some way. Making file system images break. This script ran once will replace any string you need (via eregi_replace so regular expressions are valid) to help force X-Cart to start using the FS again.
PHP Code:
<?php
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# Cart-Lab.com 7/22/2006 4:29AM
# Replace local paths stored in xcart_images and xcart_thumbnails
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# One grey cold day in Russia, X-Cart developers decided "Hey lets store images in Database"
# people complained about how slow it was, so X-Cart developers say "ok, well then we will
# store in the file system, and use a full local path to store the reference in the database!"
#
# This script is mainly meant to fix local paths, when moving X-Cart to a new directory or
# transfering to a new host with a different local path, Images will appear broken.
#
# NOTE: This is only the case if your using the File System within "Images Location"
#
# SETUP:
# Edit $pattern and $replace with your replacements
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# No time limit for script
@set_time_limit(0);
# Base X-Cart functions
require "./auth.php";
# Security Check
require $xcart_dir."/include/security.php";
# pattern to replace (eregi, regular expression)
$pattern = "\/xcart";
$replace = "";
# Get all productid's
$productids = func_query("SELECT productid FROM xcart_products");
if(is_array($productids)) {
foreach($productids as $k => $v) {
#echo "<HR>Detailed Images";
$sql = func_query("SELECT image_path FROM xcart_images WHERE productid='$v[productid]'");
if(is_array($sql)) {
foreach($sql as $kk => $vv) {
$new_path = eregi_replace($pattern,$replace,$sql[$kk]["image_path"]);
echo $new_path;
if($new_path) {
db_query("UPDATE xcart_images SET image_path='$new_path' WHERE productid='$v[productid]'");
echo "$v[productid] updated<BR>";
$new_path=false;
}
}
}
#echo "<HR>Thumbnails
$sql = func_query("SELECT image_path FROM xcart_thumbnails WHERE productid='$v[productid]'");
if(is_array($sql)) {
foreach($sql as $kk => $vv) {
$new_path = eregi_replace($pattern,$replace,$sql[$kk]["image_path"]);
echo $new_path;
if($new_path) {
db_query("UPDATE xcart_thumbnails SET image_path='$new_path' WHERE productid='$v[productid]'");
echo "$v[productid] updated<BR>";
$new_path=false;
}
}
}
}
}
?>
I know its good idea to dump to DB before changing local paths, then back out to the FS via Images Location. But I hate using a database for a file system, its just not, and shouldn't be used for such. Not to mention I was having issues using this method in previous experiences it wasn't very solid fix for me, and I would still end up hardsetting $xcart_dir in func_get_thumbnail_url(). Doing this also causes your filenames to wiped, and X-Cart generates new ones once you convert back to FS.

Hopefully
FULL paths aren't stored in later versions of X-Cart, a relative path to the X-Cart directory would be enough, don't ya think
