Antwort #17 am: 04. Dezember 2015, 17:22:01
Also
ZUERST den Shop wieder in den Originalzustand bringen! Also der Ordner original_images muss die Bilder enthalten, wo die Zuordnung products_id == Bildname nicht stimmt!
Dann den Code ausführen:
<?phprequire_once('includes/application_top.php');//get table products_images (contains additional images)$sql = "SELECT * FROM products_images";$res = xtc_db_query
($sql);$products_additional_images = xtc_db_fetch_array
($res);// get table products (first image there)$sql = "SELECT products_id, products_image FROM products";$res = xtc_db_query
($sql);$products = xtc_db_fetch_array
($res);// set dirs$dir_orig="images/product_images/original_images/";$dir_backup="images/product_images/original_images_backup/";// initialize variable$file_sql = '';// move original to backup dirrename($dir_orig,$dir_backup);// create original dir with correct permissionsmkdir($dir_orig,0755);// copy the index.htmlcopy ($dir_backup . 'index.html', $dir_orig . 'index.html');// loop over all productsforeach ($products as $product) { // copy the first image of the product to new name $file = explode('_',$product['products_image']); //split id part of image from end part (0.jpg) copy ($dir_backup . $product['products_image'], $dir_orig . $product['products_id'] . '_' . $file[1]); // prepare sql $file_sql .= "UPDATE products SET products_image='" . $product['products_id'] . '_' . $file[1] . "' WHERE products_id = '" . $product['products_id'] . "'\n"; // loop over whole table products_images to do the same stuff with the images there foreach ($products_additional_images as $add_image) { if ($add_image['products_id'] === $product['products_id']) { // we found one $file = explode('_',$add_image['image_name']); //split id part of image from end part (0.jpg) copy ($dir_backup . $add_image['image_name'], $dir_orig . $add_image['products_id'] . '_' . $file[1]); // prepare sql $file_sql .= "UPDATE products_images SET image_name='" . $add_image['products_id'] . '_' . $file[1] . "' WHERE products_id = '" . $add_image['products_id'] . "' AND image_id = '" . $add_image['image_id'] . "'\n"; } } echo "<p>Product_ID: " . $product['products_id'] . "</p>\n";}$write = file_put_contents('images_fix.sql',$file_sql);if ($write ===false) { echo "<p>FEHLER BEIM SCHREIBEN DER SQL DATEI!</p>";} else { echo "<p>SQL Datei "images_fix.sql" im Shoproot erfolgreich erzeugt. ($write bytes)</p>";}?> Jetzt hast Du einen Backup-ordner mit den unveränderten Dateien und im original_images liegen die richtigen umbenannten. Die Rechte auf dem Ordner sind auch schon gesetzt.
Außerdem sollte jetzt im Shoproot eine SQL Datei liegen. Diese dann einfach in myphpadmin in die Datenbank füttern.
DANACH SCRIPT UND SQL DATEI WIEDER LÖSCHEN!
Wieder ungetestet, könnte noch einen Bug enthalten ...