Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Images breaking after host and/or directory change

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 07-22-2006, 03:00 AM
  B00MER's Avatar 
B00MER B00MER is offline
 

X-Guru
  
Join Date: Sep 2002
Location: Keller, TX (Cart-Lab.com)
Posts: 3,165
 

Default Images breaking after host and/or directory change

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
__________________
Cart-Lab - 100+ Social Bookmarks for X-Cart.
Reply With Quote
  #2  
Old 08-11-2006, 09:43 AM
 
nevets1219 nevets1219 is offline
 

eXpert
  
Join Date: Jun 2006
Posts: 351
 

Default

Image broke on my upgrade test installation (direct copy of my current version). Going to give this a try (will post back with results).

EDIT: What I did was create a duplicate of my original x-cart installation and MySQL DB. Then I put it in a subdirectory and created another DB. This second set of DB / web content is pretty much the same with the only difference being in config.php and that I upgraded it from v4.0.18 to v4.0.19. The images are of course broken and at first I thought that would be natural but these images have full path to the image location and the images at the original location are still there (there's even a copy of those images in the copy installation as well).

Now why would the images break still?

EDIT: Just ran a test.

Let's say :
Originally I had : /usr/home/xcart/images/abc123.gif (same as in my copy installation) in the DB (images stored in FS)

However, the copy installation will not display the images. So I change it to : /usr/home/xcart/upgraded/images/abc123.gif and magically it works.

My conclusion is that X-Cart appends something that makes it fail to reach the image even though it asked for a full path. Still doesn't explain a whole lot.

EDIT: Not being all that familiar with regular expressions. Let's say I moved it into a sub-directory.
From /usr/home/xcart/
To /usr/home/xcart/upgraded/

I should have:
$pattern = "\/xcart";
$replace = "/xcart/upgraded";

Is that assumption correct?
__________________
4.1.8
Reply With Quote
  #3  
Old 08-14-2006, 11:35 PM
  B00MER's Avatar 
B00MER B00MER is offline
 

X-Guru
  
Join Date: Sep 2002
Location: Keller, TX (Cart-Lab.com)
Posts: 3,165
 

Default

Quote:
Originally Posted by nevets1219
EDIT: Not being all that familiar with regular expressions. Let's say I moved it into a sub-directory.
From /usr/home/xcart/
To /usr/home/xcart/upgraded/

I should have:
$pattern = "\/xcart";
$replace = "/xcart/upgraded";

Is that assumption correct?

Yes, you are correct. /xcart would become /xcart/upgraded. Of course this will append both leading and trailing content as well.

If your not too familiar with regular expressions:
http://weitz.de/regex-coach/

You also correct in assuming x-cart does a string compare for the full path, within the func_get_thumbnail_url function in include/func.php using $xcart_dir. (4.0.x)

Code:
$cmpfunc = (X_DEF_OS_WINDOWS ? 'strncasecmp' : 'strncmp');
...
Code:
if (X_DEF_OS_WINDOWS) { $thumbnail_info['image_path'] = str_replace('/', '\\', $thumbnail_info['image_path']); } if (!$cmpfunc($xcart_dir, $thumbnail_info["image_path"], strlen($xcart_dir))) { # image_path is an locally placed image $url = $current_location.str_replace("\\", "/", substr($thumbnail_info["image_path"], strlen($xcart_dir))); return $url;
__________________
Cart-Lab - 100+ Social Bookmarks for X-Cart.
Reply With Quote
  #4  
Old 02-01-2007, 09:11 AM
 
TTS Telecom TTS Telecom is offline
 

Member
  
Join Date: Dec 2003
Location: SW, UK
Posts: 17
 

Default Re: Images breaking after host and/or directory change

Great little script, thank you.
__________________
X-cart: 4.0.17
PHP: 4.3.11
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 01:04 PM.

   

 
X-Cart forums © 2001-2020