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") CODE Now: Code:
### Custom MOD - Image directory file path - Comment out 2 lines below and hard-code image path to your files folder... 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") { 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 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 |
Re: Image Path MOD for 4.1.x
hmm this is interesting. Haven't tried it out, but definately going to ... will let you know. Thanks for the effort.
|
Re: Image Path MOD for 4.1.x
Quote:
Also, it's an easy fix to change back, so when X-Cart 4.1.11 comes out, you can revert the files and use their image path fix, if you so desire. In case you missed it, Alex Mulin, said that the image path issue would be addressed in the next major upgrade of X-Cart. Read his post #31 on page 4 of this forum topic: http://forum.x-cart.com/showthread.php?t=39255 Robert |
Re: Image Path MOD for 4.1.x
I am having a hard time figuring these parts out...
Code:
## return $files_dir_name; I understand I need to put the path to where my images are, but how does x-cart know I want to save a thumbnail to the "thumbs" folder and a product image to the "products" folder? It seems to find the images that are already there, but when I add one it puts in it the "var/tmp" folder with some strage abstraction of the original file name. For instance, "test-1.jpg" will be "test-1jpgFgfGt" or something similar. At any rate, it shows as a broken image, and is not stored anywhere near "/home/mysite/public_html/files/". I could live with the P, T, D, C , and M folders if it didn't change the filename, and didn't append -01, -02, -03 etc. if the file was already there. Is there some reason it will not overwrite an existing file with the same name? |
Re: Image Path MOD for 4.1.x
As the original X-Cart codes shows in the func.backoffice.php, you need to specify your "$files_dir_name" (i.e. files directory name).
This is the name of your main files directory. For us, we just upgraded from a 4.0.x cart, so it was the main /files/ folder. Then in that folder we have sub-folders with our product images in them. This link is only concerned with the main folder that holds your image sub-folders. To get the rest of the link (the part before the /files/ directory), go to the Administration --> 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. NOTE: If you only do this Step 1, it will have the correct image path for existing images, but if you want it to have the correct image path to that same folder for new products (and not the standard X-Cart lettered sub-folders), then you have to complete Step 2 (in post #1 above). When you complete Step 2 in the func.image.php file, be sure to keep these 2 lines of code: Code:
$prepared['image_path'] = $file_path; Our T, P, D, etc. image folders all remain empty at this point, and images for our newly added products are all existing in our files/imageABC folders. Note: This has only been tested on X-Cart 4.1.9 on an Apache server (we're using a Dedicated IP). Robert |
Re: Image Path MOD for 4.1.x
"That will set the image path to the file path you specify. When you add a new product (or clone a product) and add a thumbnail (or detailed image), it will first generate a tmp image link until you Save the New Product, and then the actual File Path and File Name you specified will be written into the Database and stored as the product's image path."
I think that is the problem. I have specified "/home/removed account name/public_html/test1/files/" as $prepared['image_path'] = $file_path; in func.backoffice.php so in func.image.php when it see "$prepared['image_path'] = $file_path;" it is looking for "/home/removed account name/public_html/test1/files/", correct? How does it know that a thumbnail needs to go to "/home/removed account name/public_html/test1/files/thumbs/" and a product image needs to go to "/home/removed account name/public_html/test1/files/products/" when it is not specified anywhere (that I can see anyway)? Part of the upgrade process involves moving the images from the file system to the database. When I try to move them it does not move them where I want but uses the images/T, P, D etc. folders renaming them in the process. Lets pretend for a moment that I have no images. If I add a new product with a thumbnail, how do I get it to save to "/home/removed account name/public_html/test1/files/products/" using the original filename I specify? Also, if I decide later I want a different thumbnail, how do I get it to overwrite the original thumbnail instead of appending "-01" to it? |
Re: Image Path MOD for 4.1.x
As a side note: You might notice in my signature that we are using a Dynamic Image mod in version 4.0.19 but have decided not to use this after upgrading because of the ensuing problems it has caused. What it does is "read" the original full size image (stored in /files/products/) and creates a thumbnail that it stores as a MD5 hash of the filenname in files/cache (regardless of where you stipulate in the "images location" of x-cart). After upgrading, the full size product image shows as the thumbnail in xcart and there is no product image shown. As you can see, I am kind of starting from scratch, but I do have the images, just need to know where x-cart will put them (and hopefully store them using the original filenames).
|
Re: Image Path MOD for 4.1.x
OK.... I got x-cart to "see" the images that exist. There is still the problem that when adding a new image it isn't saved because it doesn't know where to save it (at least that is what I think). It "saves" it in the var/tmp folder (where it really isn't saved). If I comment out the code like this...
Have you tried saving a new image? Were you successful? |
Re: Image Path MOD for 4.1.x
I have done the mod here and now I am getting this error below.
Parse error: syntax error, unexpected $end in /home/stitches/public_html/include/func/func.backoffice.php on line 619 |
Re: Image Path MOD for 4.1.x
Quote:
I think I might know what the problem is. We FTP our images up to our site first (into the files/images/sub-folders). Then when we Add or Modify a product, we browse to this location on the server. So the exact file location is placed into the image_path. If you are browsing images on your local hard drive, then it will not have the correct image file path and will create a Temp image. Please look back at my 1st Post above, as I updated it with 3 new NOTES at the bottom. Robert |
Re: Image Path MOD for 4.1.x
then i get this error
Parse error: syntax error, unexpected T_ELSE in /home/stitches/public_html/include/func/func.image.php on line 512 |
Re: Image Path MOD for 4.1.x
Can someone please lend a hand on these two errors above? Thanks in advance
|
Re: Image Path MOD for 4.1.x
Ok I got rid of all the errors I was having fixed but I may have messed up the code because now it will not add the images to the product page. When i go to choose my product image I select it like normal but then it does not add it to the product page.
|
Re: Image Path MOD for 4.1.x
OK... that explains things. I had to modify the image_path initially because of the tela-firma mod (it "saves" the full size image as the thumbnail -- not actually, but that is the way x-cart interprets it) Now all I have to do is assign thumbnails for every product.
|
Re: Image Path MOD for 4.1.x
Shareen, those are Syntax errors... most likely you left off a semicolon at the end of a line of code, and/or forgot a closing bracket. Double-check your code.
Right-click on a product image to check your image properties and see the image file path. Images need to be added via FTP off the server. Also check for proper permissions on your image(s) folders. Robert |
Re: Image Path MOD for 4.1.x
I copied it just the way you have it in here. What should I do?
|
Re: Image Path MOD for 4.1.x
Here is the code I put in and it is not working.
/* 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; } } else { |
Re: Image Path MOD for 4.1.x
Error I am getting at the moment is:
Parse error: syntax error, unexpected '}' in /home/stitches/public_html/include/func/func.image.php on line 534 |
Re: Image Path MOD for 4.1.x
Quote:
Remove one (or comment out), and that should fix your syntax error. Robert |
Re: Image Path MOD for 4.1.x
is it ok for me to search for that whole code and delete it and then paste in the whole code that you put?
|
Re: Image Path MOD for 4.1.x
Now it adds the images but it puts them right back in the images/T folder, and it looks like it will only adds the thumbnail and then create the product image form that and give it a name adding 01 to it or something to that affect Even after I delete this folder it will create it again.
|
Re: Image Path MOD for 4.1.x
Code does not work with my version looks like ):
|
Re: Image Path MOD for 4.1.x
I plan to upgrade to 4.1.10 sometime in the next week. I'll post back if there are any changes to the code. Since 4.1.10 is mostly bug fixes, I expect this same code should work just fine.
Double-Check that you did both Step 1 and Step 2 in Post #1. Remember... this mod is for adding images to New Products or you can Modify Existing products via the Admin interface, but you need to make sure you are adding the images, directly from your files/image(s) folders on your server (not your local drive). If you don't have a product image, X-Cart will default and use the thumbnail on the detailed product page, the same as it did in X-Cart 4.0.x and previous versions. If you want a separate product image, you can add that on the individual Add Product and Modify Product pages. Also, this mod supports the X-Cart Detailed Images Module. Robert |
Re: Image Path MOD for 4.1.x
Robert i got this to work but when I look at the Table in the database: xcart_images_P and Table: xcart_images_T it shows the image path as ./images/P/anml-buy-all_org.jpg and ./images/T/anml-buy-all_org.jpg instead of just ./files/images/anml-buy-all_org.jpg
Just thought i would give you an update on my progress |
Re: Image Path MOD for 4.1.x
Hi Shareen,
Thanks for the update, here's a couple more things to check... 1. Make sure that you have your Admin --> Images Location set to use the FileSystem for storing images and not the Database. 2. When you look at the Database xcart_images_T, etc. folders, and you still see the image path pointing to the /images/T etc. folders... maybe this is just for your existing images. In other words, this Mod only puts new product images you add or modify into the files/images/sub-folders. You can check if a new product image you added is in the correct location, by Browsing the xcart_images_T folder and click the >> (arrows) to jump to the end of the table where the newest product images have been added. Look at those image_paths. If they are correct, the mod is working fine for you, but you will then need to update all your existing image file paths either by manually editing them or via an automated script. Robert |
Re: Image Path MOD for 4.1.x
Image Path MOD for 4.1.10 with Security Fix from July 2, 2008
First, 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 (Line 49) - NOTE: This MOD now incorporates the 4.1.10 Security Fix Code 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. CODE Was: Code:
# CODE Now: Code:
# MOD 02: File: include/func/func.image.php (Line 502) NOTE: This section of code has remained the same from 4.1.9 to 4.1.10 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") { NOTE: All the code in MOD 2 below is commented 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, but keep $prepared line at end Robert |
All times are GMT -8. The time now is 05:43 AM. |
Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.