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