ce7 Posted June 12, 2020 Share Posted June 12, 2020 hi there, I have CE1.0.5.0, trying to modify admin/categories.php so that can have the categories images (ref to Select Product Image Directory in selected image folder... /* Make New Image subdirectory for categories */ $new_dir_cat = preg_replace('/[^a-zA-Z0-9_.-]/i', '_',$_POST['new_directory']); $dir_cat = (tep_not_null($new_dir_cat) ? $_POST['directory'] . '/' . $new_dir_cat : $_POST['directory']); $dir_cat = ($dir_cat ? $dir_cat .'/' : ''); /* Make New subdirectory */ if ($dir_cat && !is_dir($root_images_dir . $dir_cat)) { if (mkdir($root_images_dir . $dir_cat)) $messageStack->add_session(sprintf(SUCCESS_CREATED_DIRECTORY, $new_dir_cat, $images_dir.$_POST['directory']), 'success'); } $categories_image = new upload('categories_image'); $categories_image->set_destination($root_images_dir . $dir_cat); if ($categories_image->parse() && $categories_image->save()) { tep_db_query("update categories set categories_image = '" . tep_db_input($categories_image->filename) . "' where categories_id = '" . (int)$categories_id . "'"); } $OSCOM_Hooks->call('categories', 'insertcategoryupdatecategoryAction'); tep_redirect(tep_href_link('categories.php', 'cPath=' . $cPath . '&cID=' . $categories_id)); break; with the code, i can create a new sub-image folder name, and the new categories image will save into server image/new_image_folder, however, the /catalog/images/ IMAGE DOES NOT EXIST when hit Edit, the images not show up, because path is still catalog/images/, if update cat-test-04.jpg it only allow to save under catalog/images/ not the new image sub-solder, it end up saved in bothcatalog/images/ and catalog/images/test-cat4/ has cat-test-04.jpg but only catalog/images/cat-test-04.jpg will show up in the front end how can I modify code so that#1 images in new folder will show up in the front page #2 images not only limited the location of original website setting path: catalog/images/ I also want to be able to delete just categories images, not the whole categories details (ref to Delete Category Image (ONLY for osC 2.2) I followed the installation instruction as below (I only modified a bit of the codes) but it doesn't work, did I make some mistakes? Step #1 function tep_remove_category_image($category_id) { $category_image_query = tep_db_query("select categories_image from " . TABLE_CATEGORIES . " where categories_id = '" . (int)$category_id . "'"); $category_image = tep_db_fetch_array($category_image_query); $duplicate_image_query = tep_db_query("select count(*) as total from " . TABLE_CATEGORIES . " where categories_image = '" . tep_db_input($category_image['categories_image']) . "'"); $duplicate_image = tep_db_fetch_array($duplicate_image_query); if ($duplicate_image['total'] < 2) { if (file_exists(DIR_FS_CATALOG_IMAGES . $category_image['categories_image'])) { unlink(DIR_FS_CATALOG_IMAGES . $category_image['categories_image']); } } tep_db_query("update " . TABLE_CATEGORIES . " set categories_image ='' where categories_id = '" . (int)$category_id . "'"); } Step #2 case 'delete_category_image_confirm': if (isset($_POST['categories_id'])) { $categories_id = tep_db_prepare_input($_POST['categories_id']); tep_remove_category_image($categories_id); } tep_redirect(tep_href_link('categories.php', 'cPath=' . $cPath)); break; Step #3 $contents[] = ['align' => 'center', 'text' => tep_draw_bootstrap_button(IMAGE_EDIT, 'fas fa-cogs', tep_href_link('categories.php', 'cPath=' . $category_path_string . '&cID=' . $cInfo->categories_id . '&action=edit_category'), null, null, 'btn-warning mr-2') . tep_draw_bootstrap_button(IMAGE_DELETE, 'fas fa-trash', tep_href_link('categories.php', 'cPath=' . $category_path_string . '&cID=' . $cInfo->categories_id . '&action=delete_category'), null, null, 'btn-danger xxx text-white mr-2') . tep_draw_bootstrap_button(IMAGE_MOVE, 'fas fa-arrows-alt', tep_href_link('categories.php', 'cPath=' . $category_path_string . '&cID=' . $cInfo->categories_id . '&action=move_category'), null, null, 'btn-light') . // add delete image button tep_draw_bootstrap_button(IMAGE_DELETE_IMAGE, 'fas fa-trash', tep_href_link('categories.php', 'cPath=' . $category_path_string . '&cID=' . $cInfo->categories_id . '&action=delete_category_image'), null, null, 'btn-danger xxx text-white mr-2') ]; any help is appreciated, thanks! Lyn Link to comment Share on other sites More sharing options...
Fiber Posted June 12, 2020 Share Posted June 12, 2020 42 minutes ago, ce7 said: " . TABLE_CATEGORIES . " would be categories Link to comment Share on other sites More sharing options...
ce7 Posted June 13, 2020 Author Share Posted June 13, 2020 hi, @Fiber Thank you for remind me the table name, i forgot to mention it is the code in catalog/admin/includes/functions/general.php, so i did not change to "categories". delete image still not working, but i tested the categories images. now use test01.jpg as example, it will #01 no problem to make images/test01.jpg or images/new_sub_cat/test01.jpg #02 no problem to upload to server images/test01.jpg or images/new_sub_cat/test01.jpg #03 no problem to update the database-categories table, it will show up all the categories image directory and image name if I manually edit the categories column, categories_images from /home/public_html/site.com/images/cat2/cat-test-01.jpg to just cat-test-01.jpg then the front page will appear the categories image, so this tell me the categories_images only accept image file without directory details... so my question now ishow to change file or code so that column, categories_images will accept image_directory/image_name.jpg and will show up both in admin (no more IMAGES DOES NOT EXIST) and front page? any help is appreciated, thanks! Lyn Link to comment Share on other sites More sharing options...
Fiber Posted June 13, 2020 Share Posted June 13, 2020 Do not know these addons, I only noticed the ". TABLE_CATEGORIES. " Link to comment Share on other sites More sharing options...
♥ecartz Posted June 13, 2020 Share Posted June 13, 2020 The image URLs are made by appending the image name to the image directory URL. So you only want the portion of the path after the images directory. In your example, that would be cat2/cat-test-01.jpg Always back up before making changes. Link to comment Share on other sites More sharing options...
ce7 Posted June 13, 2020 Author Share Posted June 13, 2020 hi, @ecartz Thank you the suggestion. i change back the code: from $root_images_dir to $images_dir ($images_dir = 'images/';) // tep_db_query("update categories set categories_image = '" . $root_images_dir . tep_db_input($categories_image->filename) . "' where categories_id = '" . (int)$categories_id . "'"); tep_db_query("update categories set categories_image = '" . $images_dir . tep_db_input($categories_image->filename) . "' where categories_id = '" . (int)$categories_id . "'"); it is still admin and front page not showing the image.... Link to comment Share on other sites More sharing options...
♥ecartz Posted June 13, 2020 Share Posted June 13, 2020 Maybe tep_db_query("UPDATE categories SET categories_image = '" . tep_db_input($dir_cat . $categories_image->filename) . "' WHERE categories_id = " . (int)$categories_id); Always back up before making changes. Link to comment Share on other sites More sharing options...
ce7 Posted June 13, 2020 Author Share Posted June 13, 2020 hi, @ecartz i am just self learning oscommerce, not trained programmer, so took me many tries and forgot to change " $images_dir " part, and after your modification, it works great! Thank you so much!!! You are the champion!👍 😘 Link to comment Share on other sites More sharing options...
ce7 Posted June 13, 2020 Author Share Posted June 13, 2020 hi, @ecartz About the delete image, it is the addon for osc 2.2 version, in the later version, the main images can not be deleted, the enlarge images, will have a trash icon, i like to just delete the image, is it similiar to your moidification, but instead of UPDATE, but use DELETE? Link to comment Share on other sites More sharing options...
♥ecartz Posted June 13, 2020 Share Posted June 13, 2020 No, the DB update would stay the same. The only change you'd need to make is " . TABLE_CATEGORIES . " to categories. Otherwise , the code that you posted should be correct. Except that it's missing the confirmation step. You have the button and you have the code that processes the confirmation. But I don't see the actual step for confirming the deletion. Always back up before making changes. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.