I noticed the product images are now going under image/product/0, image/product/1, etc. I copied over 100,000 images from Server A (older version of cs-cart) to Server B (newest version), and the image paths are correct in cscart_images, so my images are not showing up on server B because somewhere something is adding that subdirectory on. How can I either change this behavior or if I knew the rules on how these products are broken up, I could move them into the appropriate subfolder.
Thanks,
Scott
[quote name=‘scottemick’]I noticed the product images are now going under image/product/0, image/product/1, etc. I copied over 100,000 images from Server A (older version of cs-cart) to Server B (newest version), and the image paths are correct in cscart_images, so my images are not showing up on server B because somewhere something is adding that subdirectory on. How can I either change this behavior or if I knew the rules on how these products are broken up, I could move them into the appropriate subfolder.
Thanks,
Scott[/quote]
Hi Scott, this is a near impossible task to resolve manually, you should use the online upgrade on the older cs-cart version to update to the latest version, the upgrade process will make/move the images into a gazillion new numbered directories (0, 1, 2, 3, 4, 5, 6, 7, 8, ect…) all while breaking any links to images you did have indexed (google images ect…) Give it a try, cs-cart is so much fun when things keep changing - Sno
That is my plan ultimately, to upgrade all our sites…I just kinda wanted to get this new one rolled out first, I guess I will have to wait unless I can find the code that determines what goes where…Thanks Sno
actually if you are managing sites with thousands of products like I am which are uploaded by other software here is some information I found:
The simple formula for where the images go is
$path = $object_type . “/” . floor($image_id / MAX_FILES_IN_DIR);
MAX_FILES_IN_DIR is by default set at 1000 in config.local.php.
so the first 999 will go in images/product/0 or images/detailed/0, then 1000 - 1999 will go into image/product/1 etc, because floor rounds down to the next lowest integer.
so your integration software can calculate where to put the image after a product with image(s) is created and the image id(s) are returned.
OR
you create code to execute from the attach_absolute_image_paths hook. The function is in the core/fn.images.php page.
function fn_attach_absolute_image_paths(&$image_data, $object_type)
{
$image_id = !empty($image_data['images_image_id'])? $image_data['images_image_id'] : $image_data['image_id'];
$path = $object_type . "/" . floor($image_id / MAX_FILES_IN_DIR);
if (!empty($image_data['image_path'])) {
if (fn_get_file_ext($image_data['image_path']) == 'swf') { // FIXME, dirty
$image_data['is_flash'] = true;
}
$image_name = $image_data['image_path'];
$image_data['http_image_path'] = Registry::get('config.http_images_path') . $path . '/' . $image_name;
$image_data['absolute_path'] = DIR_IMAGES . $path . '/' . $image_name;
$image_data['image_path'] = Registry::get('config.images_path') . $path . '/' . $image_name;
}
fn_set_hook('attach_absolute_image_paths', $image_data, $object_type, $path, $image_name);
return $image_data;
}
so you could override the $path in an addon by registering the hook in an addon and use your own scheme or simply choose the images/product or images/detailed etc like the previous versions of cs-cart did.
Just until I get all my sites upgraded I changed my MAX_FILES_IN_DIR to 100000000 and put all the images in image/product/0. Then when I upgrade I will just write a small program to move them into folders later.
OK, I went ahead and used the addon method. I ended up moving all my product images into /images/product and /images/detailed.
here is the code:
in addons/my_changes/init.php
in addons/my_changes/func.php
if ( !defined('AREA') ) { die('Access denied'); }
fn_register_hooks('attach_absolute_image_paths');
?>
function fn_my_changes_attach_absolute_image_paths($image_data, $object_type, $path, $image_name){
$path = $object_type;
if (!empty($image_data['image_path'])) {
//$image_name = $image_data['image_path'];
$image_data['http_image_path'] = Registry::get('config.http_images_path') . $path . '/' . $image_name;
$image_data['absolute_path'] = DIR_IMAGES . $path . '/' . $image_name;
$image_data['image_path'] = Registry::get('config.images_path') . $path . '/' . $image_name;
}
}
?>
So now cs-cart again looks for all images in the images/product and images/detailed with no numerical subdirectories.
When I upgrade my other sites, I will reorganize the images myself back into the subfolders. But for now to make it easy to sync my product images across multiple sites, this will work.
[color=#555555][font=Arial, Helvetica, sans-serif][size=3]I have been struggling with why my images weren't showing up and finally found this post.[/size][/font][/color]
[color=#555555][font=Arial, Helvetica, sans-serif][size=3]I'm [/size][/font][/color][color=#555555][font=Arial, Helvetica, sans-serif][size=3]just curious, and hope to understand why does Cs-Cart have this setting? [/size][/font][/color]
[color=#555555][font=Arial, Helvetica, sans-serif][size=3]I know now I Can just change the setting to a very high number in config.local but I would like to know why this setting exists.[/size][/font][/color]
[color=#555555][font=Arial, Helvetica, sans-serif][size=3]Anyone have a clue?[/size][/font][/color]
I'm guessing that for some larger sites, the number of images per directory exceeded the amount supported by the underlying system or hosting enviornment and as such became a configurable setting.
Nothing to do with exceeding anything. It's just more efficient for a site that has a million pictures to search a directory with 1000 images instead of a directory that has 1,000,000 images.
Most servers (Linux) will not support 1M inodes in a directory. Most are limited to a much smaller amount.
But yes, breaking it up means smaller directory reads to resolve the filename(s). But there's significant (system) overhead on opening directories too versus retrieving the inodes of the files. Hence the depth of the tree can cause its own overhead.