Juto 8 Posted January 13, 2013 (edited) Hi, I am working on a new contribution for default product images directory. That is set the directory as the manufacturers name. So far I have this piece, which isn't enough: <?php /* //Replaced // copy image only if modified $products_image = new upload('products_image'); $products_image->set_destination(DIR_FS_CATALOG_IMAGES); if ($products_image->parse() && $products_image->save()) { $products_image_name = $products_image->filename; } else { $products_image_name = (isset($_POST['products_previous_image']) ? $_POST['products_previous_image'] : ''); } break; } } */ //With: //Store product images in a directory = "manufacturers_name": if ( isset($_POST['manufacturers_id']) ) { $products_image_dir = null; //Get the manufacturers name: $manufacturers_query = tep_db_query("select manufacturers_name from " . TABLE_MANUFACTURERS . " where manufacturers_id = '" . $_POST['manufacturers_id'] . "'"); $manufacturers = tep_db_fetch_array($manufacturers_query); //Now we have the dir as: $products_image_dir = DIR_FS_CATALOG_IMAGES . $manufacturers['manufacturers_name']; //Check if that directory exists, if not create it: if (is_dir($products_image_dir) || mkdir($products_image_dir,0755)) { $products_image_dir = $products_image_dir.'/'; clearstatcache(); //The results of is_dir is cached, thus clear the cache } } //For debugging echo 'image dir = '.$products_image_dir;//Output: Ok. // $products_image = new upload('products_image'); $products_image->set_destination($products_image_dir); if ($products_image->parse() && $products_image->save()) {//Doesn't seem to work $products_image_name = $products_image_dir . $products_image->filename; //For debugging echo '<br>products_image_name = '.$products_image_name;//Output: Nothing. } else { $products_image_name = (isset($_POST['products_previous_image']) ? $_POST['products_previous_image'] : ''); } break; } } ?> Testing on an existing product, gives that the directory is created, but the image remains in the old directory. Obviously I need to edit more code or plce the snippet elsewhere. Hopefully someone knows how. So, any suggestion would be most welcome. Sara Edited January 13, 2013 by Juto Contributions: http://addons.oscommerce.com/info/8010 http://addons.oscommerce.com/info/8204 http://addons.oscommerce.com/info/8681 Share this post Link to post Share on other sites
♥bruyndoncx 260 Posted January 14, 2013 I have some code that puts them in hardcoded directories. this is a shortened version (removed some values) of my include/pictures_in_subdir.php file <?php //BoF CB pictures in subdir $man_dir = array( '10' => 'alessi', '11' => 'elisa', '12' => '', '13' => 'illy', '14' => 'francisfrancis', ... '170' => 'zilverstad' ); $products_image->set_destination(DIR_FS_CATALOG_IMAGES . $man_dir[$man_id] ); // $this->set_filename($man_dir[$man_id] . '/' . $file['name']); //EoF CB Pictures in subdir Then the only reference to this file in categories.php is case 'new_product_preview': // copy image only if modified $products_image = new upload('products_image'); $man_id = tep_db_prepare_input($_POST['manufacturers_id']); require('includes/pictures_in_subdir.php'); if ($products_image->parse() && $products_image->save()) { $products_image_name = $products_image->filename; $products_image_name = $man_dir[$man_id] . '/' . $products_image_name ; // ***** Prepend subdirectory to filename $_POST['products_image'] = $products_image_name; } else { $products_image_name = (isset($_POST['products_previous_image']) ? $_POST['products_previous_image'] : ''); } break; Hope this helps you going KEEP CALM AND CARRY ON I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support). So if you are still here ? What are you waiting for ?! Find the most frequent unique errors to fix: grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt Share this post Link to post Share on other sites
♥bruyndoncx 260 Posted January 14, 2013 tryiing to find difference between your and my code and see small diff your directory seems to have ending slash when set with ->set_destination, perhaps that is the issue ? KEEP CALM AND CARRY ON I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support). So if you are still here ? What are you waiting for ?! Find the most frequent unique errors to fix: grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt Share this post Link to post Share on other sites
Juto 8 Posted January 15, 2013 @bruyndoncxHi Carine, thanks for your advice. I have managed to get it working apart from the preview page. Reading your post I realize that I need to split up the logic a bit, at least for debugging. So big thank you to you. :) There's a bit confusing when the preview page is like this: <td class="main"><?php echo tep_image(DIR_WS_CATALOG_IMAGES . $products_image_name, $pInfo->products_name, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'align="right" class="image-margins"') . $pInfo->products_description; ?></td> That is, using DIR_WS_CATALOG_IMAGES, instead of DIR_FS_CATALOG_IMAGES used during upload... So, I do have some work to do. Thanks again for your advice :) Sara Contributions: http://addons.oscommerce.com/info/8010 http://addons.oscommerce.com/info/8204 http://addons.oscommerce.com/info/8681 Share this post Link to post Share on other sites