View Single Post
  #1  
Old 04-26-2008, 12:30 PM
 
robertswww robertswww is offline
 

X-Adept
  
Join Date: Jul 2003
Posts: 586
 

Default Image Path MOD for 4.1.x

Many people on the X-Cart Forums have complained about the way the X-Cart 4.1.x branch handles images.

The Problem:
Many users have their own Image Folder Structure for grouping images by Category, Manufacturer, Provider, etc. Unfortunately, the 4.1.x branch tries to move all Thumbnails to the T folder, all Product images to the P folder, all Detailed images to the D folder, etc. If your store has thousands of images, these folders become a bloated mess with no organizational structure that makes it difficult for site Administrators to locate and add images.

The MODs below will fix this in 2 simple steps...
Step 1 will modify the image file path location (for example, to point to the old /files/images directory previously used in 4.0.x carts).
Step 2 will modify the code to keep your image name and location and not move it to the lettered sub-folders (on your server) when adding a New Product Thumbnail, Detailed Image, etc.

Thanks to my programmer brother for figuring this out for our store site. He said it was really easy to accomplish and the code could easily be made to check for which type of Image handling your prefer... the 4.0.x-style or the 4.1.x-style, so maybe the X-Cart Qualiteam programmers will implement this in a future release.

First, if you would like to try this MOD, as always, it's a good idea to first make a backup of your store files and DB. Also work on copies of the 2 files that are being modified, so you can change back quickly, if need be.

Next, make sure your Images Location is set to use the File System (FS).

MOD 01
File: include/func/func.backoffice.php (about line 49)

NOTE: The proper image file path (the part before the /files/ directory) can be found on the Summary page of your X-Cart back-end. Look under the Component column for your X-Cart directory, and enter the value you see in the Status column.

Part of: function func_get_files_location () {
# This function determine the files location for current user

CODE Was:
Code:
if ($single_mode || $user_account["usertype"] == "A") return $files_dir_name; return $files_dir_name.DIRECTORY_SEPARATOR.$login; }

CODE Now:
Code:
### Custom MOD - Image directory file path - Comment out 2 lines below and hard-code image path to your files folder... if ($single_mode || $user_account["usertype"] == "A") ## return $files_dir_name; return "/home/yoursite/public_html/files/"; ## return $files_dir_name.DIRECTORY_SEPARATOR.$login; return "/home/yoursite/public_html/files/"; }


MOD 02:
File: include/func/func.image.php (about line 502)

Part of: function func_prepare_image($file_upload_data, $type = 'T', $id = 0) {
# Prepare posted image for saving

CODE Was:
Code:
if ($config_data["location"] == "FS") { $prepared['image_path'] = ""; if (!is_url($file_path) || $config_data['save_url'] == 'Y') { $dest_file = func_image_dir($type); if (!zerolen($prepared['filename'])) { $dest_file .= "/".$prepared['filename']; } $prepared['image_path'] = func_store_image_fs($image_data, $type); if (zerolen($prepared['image_path'])) return false; $prepared['filename'] = basename($prepared['image_path']); $path = func_relative_path($prepared['image_path'], $xcart_dir); if ($path !== false) { $prepared['image_path'] = $path; } } else { $prepared['image_path'] = $file_path; } }

NOTE: All the code in MOD 2 below is comment out except for the final closing bracket, and this line: $prepared['image_path'] = $file_path;

CODE Now:
Code:
### Custom MOD - Comment out section below to prevent X-Cart from changing file name and saving to a lettered image subfolder /* if (!is_url($file_path) || $config_data['save_url'] == 'Y') { $dest_file = func_image_dir($type); if (!zerolen($prepared['filename'])) { $dest_file .= "/".$prepared['filename']; } $prepared['image_path'] = func_store_image_fs($image_data, $type); if (zerolen($prepared['image_path'])) return false; $prepared['filename'] = basename($prepared['image_path']); $path = func_relative_path($prepared['image_path'], $xcart_dir); if ($path !== false) { $prepared['image_path'] = $path; } } else { */ $prepared['image_path'] = $file_path; ### } }

I hope others get some good use out of this mod!

Update May 27, 2008:
NOTE 1: We 1st upload our product images (thumbs, detailed, etc.) to the files/images folder via FTP. When we Add a New Product, or change an existing one, we then Browse to this file on the Server (not from our local drive). This will give the product the correct image path to the exact location on your server. Otherwise you will have issues with a Temp image being created with the wrong image path.

NOTE 2: In the Database, your newly added images will then have the correct image_path in the xcart_images_D, xcart_images_T, etc. tables. Your images/D, images/T, etc. folders on your server will remain empty.

NOTE 3: If you are upgrading from X-Cart 4.0.x to X-Cart 4.1.x, the Database updater will assign your existing product images to one of the lettered sub-folders. Our web programmer then wrote a PHP script to go in and change all the existing image paths to point to their location in the /files/images folder(s). For new stores, without products, this will not be an issue, but if you have an existing store, you will need to go into the Database and export the xcart_images_D, xcart_images_T, etc. tables, and use a utility to find and replace the image_path. If your store only has a few existing products, you can manually Modify the Product via the Admin interface and select the new image via the FTP method mentioned in NOTE 1 above.

NOTE 4:This MOD has also been tested on stock installs of X-Cart 4.1.9 and X-Cart 4.1.10
A Security Fix was released by X-Cart on July 2, 2008 and it affects the include/func/func.backoffice.php file... see Post # 26 on Page 3 for X-Cart ver. 4.1.10 with Security Fix and the updated MOD code.

Robert
__________________
X-cart 4.1.10
Reply With Quote