viewtopic.php?f=8&t=1613
Regrettably, and perhaps not unexpected, the brilliance of CF’s fix was not going to extend to my version of ISC.

This script then, is a first stage of development and a work around. I shall call it Ver.1

It is a very basic in its belt and brace approach - But it works !!
Firstly, you need to make a copy of the SQL Table ‘product_images’ local on your PC and run this in a MySQL server. This Table should include the SQL header that is used to create/ install the data in the format used by ISC. By example...
Code: Select all
-- phpMyAdmin SQL Dump
-- version 2.6.4-pl3
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Apr 23, 2012 at 12:13 AM
-- Server version: 5.0.91
-- PHP Version: 5.3.3-7+squeeze8
--
-- Database: `dbXXXXXXX641`
--
CREATE DATABASE `db333551641` DEFAULT CHARACTER SET latin1 COLLATE latin1_general_ci;
USE db333551641;
-- --------------------------------------------------------
--
-- Table structure for table `isc_product_images`
--
CREATE TABLE `isc_product_images` (
`imageid` int(11) NOT NULL auto_increment,
`imageprodid` int(11) NOT NULL default '0',
`imageprodhash` varchar(32) NOT NULL default '',
`imagefile` varchar(255) NOT NULL default '',
`imageisthumb` tinyint(4) NOT NULL default '0',
`imagesort` int(11) NOT NULL default '0',
`imagefiletiny` varchar(255) default '',
`imagefilethumb` varchar(255) default '',
`imagefilestd` varchar(255) default '',
`imagefilezoom` varchar(255) default '',
`imagedesc` longtext,
`imagedateadded` int(11) default '0',
`imagefiletinysize` varchar(11) default '',
`imagefilethumbsize` varchar(11) default '',
`imagefilestdsize` varchar(11) default '',
`imagefilezoomsize` varchar(11) default '',
PRIMARY KEY (`imageid`),
KEY `i_product_images_imageprodid` (`imageprodid`,`imageisthumb`),
KEY `i_product_images_imageprodid_imagesort_imageprodhash` (`imageprodid`,`imagesort`,`imageprodhash`),
KEY `i_product_images_imageid_imageprodid_imageprodhash` (`imageid`,`imageprodid`,`imageprodhash`)
) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8 AUTO_INCREMENT=19 ;
--
-- Dumping data for table `isc_product_images`
INSERT INTO `isc_product_images` VALUES (4, 30, '', 'w/170/1482_teal_front__70694.JPG', 1, 0, 'a/383/1482_teal_front__10117_tiny.JPG', 'm/810/1482_teal_front__87597_thumb.JPG', 'x/190/1482_teal_front__21463_std.JPG', 'e/866/1482_teal_front__78671_zoom.JPG', '', 1286573768, '68x100', '165x245', '236x350', '675x1000');
INSERT INTO `isc_product_images` VALUES (5, 30, '', 'y/918/1482_teal_back__22009.JPG', 0, 1, 'x/021/1482_teal_back__02295_tiny.JPG', 'k/320/1482_teal_back__22235_thumb.JPG', 'e/041/1482_teal_back__22361_std.JPG', 'o/954/1482_teal_back__16928_zoom.JPG', '', 1286573783, '68x100', '165x245', '236x350', '675x1000');
INSERT INTO `isc_product_images` VALUES (6, 30, '', 'j/576/1482_teal_back__23500.JPG', 0, 2, 'h/018/1482_teal_back__37600_tiny.JPG', 'b/667/1482_teal_back__99684_thumb.JPG', 'v/676/1482_teal_back__72948_std.JPG', 'z/610/1482_teal_back__47705_zoom.JPG', '', 1286573798, '68x100', '165x245', '236x350', '675x1000');
INSERT INTO `isc_product_images` VALUES (7, 30, '', 'd/403/1482_teal_back__13757.JPG', 0, 3, 'm/463/1482_teal_back__61392_tiny.JPG', 'k/331/1482_teal_back__03959_thumb.JPG', 'y/682/1482_teal_back__01263_std.JPG', 's/784/1482_teal_back__64295_zoom.JPG', '', 1286573814, '68x100', '165x245', '236x350', '675x1000');
INSERT INTO `isc_product_images` VALUES (8, 31, '', 'm/392/IMG_8677__56936.JPG', 1, 0, 'j/567/IMG_8677__90626_tiny.JPG', 'e/657/IMG_8677__24322_thumb.JPG', 'b/814/IMG_8677__21425_std.JPG', 'i/199/IMG_8677__28170_zoom.JPG', '', 1286573992, '68x100', '165x245', '236x350', '675x1000');
INSERT INTO `isc_product_images` VALUES (9, 31, '', 'g/209/IMG_8684__71484.JPG', 0, 1, 'f/784/IMG_8684__01498_tiny.JPG', 'r/582/IMG_8684__37635_thumb.JPG', 'l/086/IMG_8684__16142_std.JPG', 'r/461/IMG_8684__97958_zoom.JPG', '', 1286574009, '68x100', '165x245', '236x350', '675x1000');
INSERT INTO `isc_product_images` VALUES (10, 31, '', 'w/338/IMG_8684__13265.JPG', 0, 2, 'c/891/IMG_8684__72454_tiny.JPG', 'o/699/IMG_8684__32404_thumb.JPG', 'z/940/IMG_8684__47904_std.JPG', 'w/803/IMG_8684__80885_zoom.JPG', '', 1286574020, '68x100', '165x245', '236x350', '675x1000');
INSERT INTO `isc_product_images` VALUES (11, 31, '', 'z/382/IMG_8684__78546.JPG', 0, 3, 'f/598/IMG_8684__52680_tiny.JPG', 'b/907/IMG_8684__02360_thumb.JPG', 'h/201/IMG_8684__26342_std.JPG', 'n/351/IMG_8684__67179_zoom.JPG', '', 1286574029, '68x100', '165x245', '236x350', '675x1000');
INSERT INTO `isc_product_images` VALUES (12, 32, '', 'v/446/1482_teal_front__22376.JPG', 1, 0, 'v/534/1482_teal_front__37809_tiny.JPG', 'a/139/1482_teal_front__30200_thumb.JPG', 'c/739/1482_teal_front__67208_std.JPG', 'e/377/1482_teal_front__44141_zoom.JPG', '', 1286574202, '68x100', '165x245', '236x350', '675x1000');
INSERT INTO `isc_product_images` VALUES (13, 32, '', 'y/716/VT1501_brown_back__17759.JPG', 0, 1, 's/499/VT1501_brown_back__36197_tiny.JPG', 'u/120/VT1501_brown_back__33720_thumb.JPG', 'j/516/VT1501_brown_back__75710_std.JPG', 'w/738/VT1501_brown_back__18075_zoom.JPG', '', 1286574219, '68x100', '165x245', '236x350', '675x1000');
INSERT INTO `isc_product_images` VALUES (14, 32, '', 'w/391/VT1501_brown_back__80791.JPG', 0, 2, 'j/658/VT1501_brown_back__48857_tiny.JPG', 'x/462/VT1501_brown_back__89723_thumb.JPG', 'q/057/VT1501_brown_back__53404_std.JPG', 'y/370/VT1501_brown_back__98673_zoom.JPG', '', 1286574231, '68x100', '165x245', '236x350', '675x1000');
INSERT INTO `isc_product_images` VALUES (15, 32, '', 'c/724/VT1501_brown_back__02871.JPG', 0, 3, 'e/618/VT1501_brown_back__78129_tiny.JPG', 'g/895/VT1501_brown_back__66827_thumb.JPG', 'o/245/VT1501_brown_back__38245_std.JPG', 'i/074/VT1501_brown_back__69912_zoom.JPG', '', 1286574241, '68x100', '165x245', '236x350', '675x1000');
INSERT INTO `isc_product_images` VALUES (16, 33, '', 'h/321/IMG_9223__05453.jpg', 1, 0, 'h/560/IMG_9223__80300_tiny.jpg', 'j/586/IMG_9223__21566_thumb.jpg', 'n/561/IMG_9223__49654_std.jpg', 'v/462/IMG_9223__91806_zoom.jpg', '', 1329957880, '68x100', '165x245', '236x350', '675x1000');
INSERT INTO `isc_product_images` VALUES (17, 34, '', 'l/572/IMG_9245__88769.jpg', 1, 0, 'i/473/IMG_9245__93122_tiny.jpg', 'b/270/IMG_9245__15874_thumb.jpg', 'm/658/IMG_9245__62104_std.jpg', 'y/998/IMG_9245__45431_zoom.jpg', '', 1332605022, '68x100', '165x245', '236x350', '675x1000');
INSERT INTO `isc_product_images` VALUES (18, 34, '', 'y/354/IMG_9251__11154.jpg', 0, 1, 'd/526/IMG_9251__55296_tiny.jpg', 'z/736/IMG_9251__17580_thumb.jpg', 'f/803/IMG_9251__59845_std.jpg', 'j/127/IMG_9251__31866_zoom.jpg', '', 1332605034, '68x100', '165x245', '236x350', '675x1000');
-- --------------------------------------------------------
Code: Select all
<?php
//PHP has a maximum execution time of 30 seconds, and will halt with an error
//lets give it a no limit execution time (your browser may time out
//but the script should continue to run
set_time_limit(0); //ignore php timeout
while(ob_get_level())ob_end_clean(); //remove output buffers
ob_implicit_flush(true); //output stuff directly
//function to ensure a path exists (make sure you have write permissions!
function CheckDir($dir) {
$dir = dirname($dir);
if(!file_exists($dir)) {
$dir = str_replace('\\', '/', $dir);
$arPaths = explode('/', $dir);
$path = '';
foreach($arPaths as $name) {
if(strlen($path)>0) $path .= '/';
$path .= $name;
if(!file_exists($path)) mkdir($path);
}
}
}
$server = "localhost"; //set up connection to a local server
$user_name = "XXXXXXXXX";
$password = "XXXXXXXXX";
$database = "XXXXXXXXX";
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
//connection made, now query data
if ($db_found) {
$result = mysql_query("SELECT isc_product_images.imagefile
, isc_product_images.imagefiletiny
, isc_product_images.imagefilethumb
, isc_product_images.imagefilestd
, isc_product_images.imagefilezoom
FROM
XXXXXXXX.isc_product_images");
$num_rows = mysql_num_rows($result); //how many 'lines' of data in our table
$num_imgs = $num_rows * 5; // the number of lines is equall to 5 images
$imagepath = "http://www.XXXXXXXX.com/product_images/"; //where your store keeps images online
$mydrivepath = "f:/product_images2/"; //where you want to save the mirror locally on PC
echo '<!DOCTYPE html><html><head></head><body>'; // webkit hotfix
echo $num_rows . " Lines in this table<br/>"; // show the lines found in table
echo $num_imgs . " Image referances in this table<br/><br/>"; //show hany images this equalls
while ($row = mysql_fetch_assoc($result)) {
//make sure directories exists
CheckDir($mydrivepath . $row['imagefile']);
CheckDir($mydrivepath . $row['imagefiletiny']);
CheckDir($mydrivepath . $row['imagefilethumb']);
CheckDir($mydrivepath . $row['imagefilestd']);
CheckDir($mydrivepath . $row['imagefilezoom']);
//copy the files
file_put_contents("$mydrivepath{$row['imagefile']}", file_get_contents("$imagepath{$row['imagefile']}"));
file_put_contents("$mydrivepath{$row['imagefiletiny']}", file_get_contents("$imagepath{$row['imagefiletiny']}"));
file_put_contents("$mydrivepath{$row['imagefilethumb']}", file_get_contents("$imagepath{$row['imagefilethumb']}"));
file_put_contents("$mydrivepath{$row['imagefilestd']}", file_get_contents("$imagepath{$row['imagefilestd']}"));
file_put_contents("$mydrivepath{$row['imagefilezoom']}", file_get_contents("$imagepath{$row['imagefilezoom']}"));
echo $imagepath . $row['imagefile']."<br/>"; //image found
echo $mydrivepath . $row['imagefile']."<br/><br/>"; //image saved
}
}
echo '</body></html>'; // webkit hotfix
mysql_close($db_handle);
?>
NOTE the 'might' in the above sentance. PHP can also hide information untill a process has been completed.
However, to prevent browser 'time outs' (prevalent in IE and Opera) I have tried to keep the browser active by displaying Image found/saved to screen. IF however, you do get a time out - DON'T PANIC !!! The script was still running in the background.. This problem and a few improvements are for Ver.2 as I find time to work on the script. When the browser returns to view, you will have only the first image per SQL line referanced. So if you count this number and it matches the number given at the top of the page. All is good...
I personally check to see activity by having the folder created locally on view and now and then do a right mouse click ‘properties’ check. Once the number of files (images) is same as the number calculated, job done. Or the software used to run the script reports program is completed.....
So okay, what are we doing?
Well, we are simply using a non-invasive approach to read your stores current database, and then to copy every and all image referenced onto your computer. This will give you just the images. There are one or two non-copied folders/files (obvious if checked) you can add to script and copy over from within the product_images folder itself, but for now you need to copy these manually. This is simply because they held no images and would not bee 'seen' by my script.
With the mirrored copy of images now local you can upload this back online. So in theory you will now have a fresh up to date image folder, but more importantly without the dead/old images. Do a quick integrity check and then rename old folder, rename the new and you should be good to go. Last check and then only on being satisfied you DO have a good copy. Remove the older folder. Free up host server space !!
I use XAMPP for my local MySQL server and with this setup (but not running) develop and test on phpDesigner 7
Anybody willing to assist in this development and can ‘add’ function or improvements. Please do so freely and without cost !!!
