Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Protect Images with Unlimited Images Per Product


Guest

Recommended Posts

Trying to set up Protect Images with Unlimited Images Per Product from HERE

I'm having problems with the thumb nails not being created. I tried to find a support thread on this but could not find one. Any one have any experience with this or know where I should start looking? Thank you for the help.

 

I don't get any errors, but when I up load it does not make thumb nails. :'(

Link to comment
Share on other sites

OK I think I found where the problem is, but it is beyond my knowledge. This is the code from catalog/admin/prod-img-manager

$action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');

$products_id = (isset($HTTP_GET_VARS['pid']) ? $HTTP_GET_VARS['pid'] : '');

$query = tep_db_query("select * from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " ptoc where p.products_id = pd.products_id and p.products_id = ptoc.products_id and pd.language_id = '" . (int)$languages_id . "' and p.products_id = " . (int)$products_id);

if ((tep_db_num_rows($query) == 0) && ($action != 'find')) $action = "select_product";

$product_info = tep_db_fetch_array($query);

 

if (tep_not_null($action)) {

switch ($action) {

case 'delete_image_confirm':

if (isset($HTTP_POST_VARS['image_file']) && ($HTTP_POST_VARS['image_file'] != '')) {

if (is_file(DIR_FS_CATALOG_IMAGES_THUMBS . $product_info['image_folder'] . $HTTP_POST_VARS['image_file'])) {

@unlink(DIR_FS_CATALOG_IMAGES_THUMBS . $product_info['image_folder'] . $HTTP_POST_VARS['image_file']);

@unlink(DIR_FS_CATALOG_IMAGES_PROD . $product_info['image_folder'] . $HTTP_POST_VARS['image_file']);

if ($HTTP_POST_VARS['image_file'] == $product_info['products_image']) { // deleted default image

$new_default = 'null'; // new default will be null if no file found

if ($handle = opendir(DIR_FS_CATALOG_IMAGES_THUMBS . $product_info['image_folder'])) {

while ($file = readdir($handle)) {

if (in_array(strtolower(substr($file, strrpos($file, '.')+1)), array('gif', 'png', 'jpg', 'jpeg'))) {

$new_default = $file; // new default will be the last image file found

}

}

closedir($handle);

}

$sql_data = array('products_image' => $new_default);

tep_db_perform(TABLE_PRODUCTS, $sql_data, 'update', "products_id = '" . (int)$products_id . "'");

}

}

}

 

tep_redirect(tep_href_link(FILENAME_IMAGE_MANAGE, 'pid=' . $products_id));

break;

case 'insert_image':

$sql_data_array = array('image_display' => tep_db_prepare_input($HTTP_POST_VARS['image_display']),

'products_last_modified' => 'now()');

tep_db_perform(TABLE_PRODUCTS, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "'");

$set_default = (isset($HTTP_POST_VARS['set_default']) && ($HTTP_POST_VARS['set_default'] == 'yes'));

 

$products_image = new upload('products_image');

$webimgtypes = array ('jpg', 'jpeg', 'gif', 'png');

$products_image->set_extensions($webimgtypes);

$products_image->set_destination(DIR_FS_CATALOG_IMAGES_TEMP);

$products_image->set_output_messages('session');

if ($products_image->parse() && $products_image->save()) {

$image = $products_image->filename;

$source = DIR_FS_CATALOG_IMAGES_TEMP . $image;

if (is_file($source)) {

if ($HTTP_POST_VARS['image_display'] == 0) {

if ($size = getimagesize($source)) {

if (($size[0] <= SMALL_IMAGE_WIDTH) && ($size[1] <= SMALL_IMAGE_HEIGHT)) { // copy

$success = copy($source, DIR_FS_CATALOG_IMAGES_THUMBS . $product_info['image_folder'] . $image);

if ($success) @chmod(DIR_FS_CATALOG_IMAGES_THUMBS . $product_info['image_folder'] . $image, 0777);

} else { // resize

$success = (tep_create_thumbnail($source, DIR_FS_CATALOG_IMAGES_THUMBS . $product_info['image_folder'] . $image, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) >= 0);

}

if ($success) { // set image as default in database if thumbnail creation successful

if ($set_default || ($product_info['products_image'] == '')) tep_db_query('update ' . TABLE_PRODUCTS . ' set products_image = "' . tep_db_input($image) . '" where products_id = ' . (int)$products_id);

$messageStack->add_session(TEXT_THUMBNAIL_SUCCESS, 'success');

} else {

$messageStack->add_session(TEXT_THUMBNAIL_FAILURE, 'error');

}

if (($size[0] <= MAX_ORIGINAL_IMAGE_WIDTH) && ($size[1] <= MAX_ORIGINAL_IMAGE_HEIGHT)) { // copy

$success = copy($source, DIR_FS_CATALOG_IMAGES_PROD . $product_info['image_folder'] . $image);

if ($success) @chmod(DIR_FS_CATALOG_IMAGES_PROD . $product_info['image_folder'] . $image, 0777);

} else { // resize

$success = (tep_create_thumbnail($source, DIR_FS_CATALOG_IMAGES_PROD . $product_info['image_folder'] . $image, MAX_ORIGINAL_IMAGE_WIDTH, MAX_ORIGINAL_IMAGE_HEIGHT) >= 0);

}

if ($success) {

$messageStack->add_session(TEXT_ORIGINAL_SUCCESS, 'success');

} else {

$messageStack->add_session(TEXT_ORIGINAL_FAILURE, 'error');

}

} else { // unable to get uploaded image size

$messageStack->add_session(TEXT_THUMBNAIL_FAILURE, 'error');

$messageStack->add_session(TEXT_ORIGINAL_FAILURE, 'error');

}

} else { // image display is set for blank or "no_picture" image

$messageStack->add_session(TEXT_IMAGE_IGNORED, 'error');

}

@unlink($source); // remove temporary image file

} else { // temporary upload file not found

$messageStack->add_session(TEXT_THUMBNAIL_FAILURE, 'error');

$messageStack->add_session(TEXT_ORIGINAL_FAILURE, 'error');

}

}

 

tep_redirect(tep_href_link(FILENAME_IMAGE_MANAGE, 'pid=' . $products_id));

break;

case 'make_default':

if (isset($HTTP_POST_VARS['image_file']) && ($HTTP_POST_VARS['image_file'] != '')) {

if (is_file(DIR_FS_CATALOG_IMAGES_THUMBS . $product_info['image_folder'] . $HTTP_POST_VARS['image_file'])) {

$sql_data = array('products_image' => $HTTP_POST_VARS['image_file']);

tep_db_perform(TABLE_PRODUCTS, $sql_data, 'update', "products_id = '" . (int)$products_id . "'");

}

}

tep_redirect(tep_href_link(FILENAME_IMAGE_MANAGE, 'pid=' . $products_id));

break;

case 'rebuild_confirm':

if (isset($HTTP_POST_VARS['rebuild_for']) && ($HTTP_POST_VARS['rebuild_for'] == 'all')) {

$query = tep_db_query('select image_folder from ' . TABLE_PRODUCTS);

while ($product = tep_db_fetch_array($query)) {

if ($handle = opendir(DIR_FS_CATALOG_IMAGES_PROD . $product['image_folder'])) {

while ($file = readdir($handle)) {

if (in_array(strtolower(substr($file, strrpos($file, '.')+1)), array('gif', 'png', 'jpg', 'jpeg'))) {

echo DIR_FS_CATALOG_IMAGES_PROD . $product['image_folder'] . $file . ': ';

$success = (tep_create_thumbnail(DIR_FS_CATALOG_IMAGES_PROD . $product['image_folder'] . $file, DIR_FS_CATALOG_IMAGES_THUMBS . $product['image_folder'] . $file, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) >= 0);

if ($success) {

echo TEXT_THUMBNAIL_SUCCESS;

$messageStack->add_session(DIR_FS_CATALOG_IMAGES_PROD . $product['image_folder'] . $file . ': ' . TEXT_THUMBNAIL_SUCCESS, 'success');

} else {

echo TEXT_THUMBNAIL_FAILURE;

$messageStack->add_session(DIR_FS_CATALOG_IMAGES_PROD . $product['image_folder'] . $file . ': ' . TEXT_THUMBNAIL_FAILURE, 'error');

}

echo "<br />\n";

}

}

closedir($handle);

}

}

} else {

if ($handle = opendir(DIR_FS_CATALOG_IMAGES_PROD . $product_info['image_folder'])) {

while ($file = readdir($handle)) {

if (in_array(strtolower(substr($file, strrpos($file, '.')+1)), array('gif', 'png', 'jpg', 'jpeg'))) {

echo $file . ': ';

$success = (tep_create_thumbnail(DIR_FS_CATALOG_IMAGES_PROD . $product_info['image_folder'] . $file, DIR_FS_CATALOG_IMAGES_THUMBS . $product_info['image_folder'] . $file, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) >= 0);

if ($success) {

echo TEXT_THUMBNAIL_SUCCESS;

$messageStack->add_session($file . ': ' . TEXT_THUMBNAIL_SUCCESS, 'success');

} else {

echo TEXT_THUMBNAIL_FAILURE;

$messageStack->add_session($file . ': ' . TEXT_THUMBNAIL_FAILURE, 'error');

}

echo "<br />\n";

}

}

closedir($handle);

}

}

echo '<META HTTP-EQUIV="Refresh" CONTENT="5;URL=' . tep_href_link(FILENAME_IMAGE_MANAGE, 'pid=' . $products_id) . '">';

tep_redirect(tep_href_link(FILENAME_IMAGE_MANAGE, 'pid=' . $products_id));

break;

case 'find':

$keywords = (isset($HTTP_GET_VARS['keywords']) ? $HTTP_GET_VARS['keywords'] : '');

$within = (isset($HTTP_GET_VARS['within']) ? $HTTP_GET_VARS['within'] : 'all');

if (tep_not_null($keywords)) {

if (!tep_parse_search_string($keywords, $search_keywords)) {

$error = true;

$messages[] = ERROR_INVALID_KEYWORDS;

$action = "select_product";

break;

}

}

$raw_query = "select * from " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " ptoc where p.products_id = pd.products_id and p.products_id = ptoc.products_id and pd.language_id = " . (int)$languages_id;

$where_str = '';

if (isset($search_keywords) && (sizeof($search_keywords) > 0)) {

$where_str .= " and (";

for ($i=0, $n=sizeof($search_keywords); $i<$n; $i++ ) {

switch ($search_keywords[$i]) {

case '(':

case ')':

case 'and':

case 'or':

$where_str .= " " . $search_keywords[$i] . " ";

break;

default:

$keyword = tep_db_prepare_input($search_keywords[$i]);

$where_str .= "(pd.products_name like '%" . tep_db_input($keyword) . "%' or p.products_model like '%" . tep_db_input($keyword) . "%' or m.manufacturers_name like '%" . tep_db_input($keyword) . "%'";

if ($within == 'all') $where_str .= " or pd.products_description like '%" . tep_db_input($keyword) . "%'";

$where_str .= ')';

break;

}

}

$where_str .= " )";

}

$query = tep_db_query($raw_query . $where_str . ' group by p.products_id');

if (tep_db_num_rows($query) == 0) {

$action = "select_product";

$messageStack->add(TEXT_NOT_FOUND, 'error');

break;

}

if (tep_db_num_rows($query) == 1) {

$product = tep_db_fetch_array($query);

tep_redirect(tep_href_link(FILENAME_SALES, 'pid=' . $product['products_id']));

} else {

$action = 'choose';

$messageStack->add(TEXT_MULTIPLE_FOUND, 'warning');

}

break;

}

}

 

Also I found that I'm not able to delete a image that was already uploaded.

Link to comment
Share on other sites

OK I think I found where the problem is, but it is beyond my knowledge. This is the code from catalog/admin/prod-img-manager

 

 

Also I found that I'm not able to delete a image that was already uploaded.

 

I suspect you may be running into a permissions problem here. In order to create a thumbnail image the product_thumbnails directory and every product image directory that it contains must be able to be read AND written by your web site. Assuming you were previously using osCommerce, set the permissions the same as you had on the original catalog/images folder. This holds true for all of the new folders for this contribution.

 

The same problem is probably causing the problem with deleting an image. Both the image file itself AND the directory that contains it must be writable by your web site in order for the prod-img-manager program to be able to delete the file.

 

Normally the directory permissions should be set to the minimum required to allow your admin site to write to the image directories. If your site directories are owned by PHP you should be able to set the directory permissions to 755. If PHP is in the same group as the owner of your site directories then permissions would have to be 775. And if PHP is merely considered a guest user of your site directories then you would have to set permissions on all of the image directories to 777. The default permissions on new image files uploaded by osCommerce is 777 so it is probably a directory permission problem that is causing the delete to fail.

Link to comment
Share on other sites

  • 9 months later...

Is this going to be updated to work with osCommerce V2.3.1??

I downloaded the update that was posted just last week, and I was hoping it would be compatible with the latest version, since the program was updated several months ago. However, I find it is not compatible. I am having some serious display issues, since they changed from using tables to using divs. The tables just don't work well on a page that is set up differently.

I have been struggling with this add-on, and/or others for filing the images in different folders and to get it to work with 'Master Products and Magic Variants for OSCOM V2.3x' which can be found here for several weeks now, but I just can't get them to work together. I think the main issue is the difference in how the product display is set up.

Is there anyone who could help me with this? I guess I just don't know enough about webdev to get this done, any help would be greatly appreciated.

thanks,

Marianne

Link to comment
Share on other sites

I've run into a problem with the manufacturers.php. When I try to add a manufacturer I first end up with the error that mfg_abbrev does not exist in the database. I can get around that by not using the abbreviation. However, then I end up with the warning ERROR_NOT_EMPTY, and it does not add the manufacturer. I haven't made any changes to the manufacturers file, just uploaded the one that came with the addon. Comparing it to the original, I think it has something to do with the mfg_abrev, since it does say ...&& tep_not_null($mfg_abbrev))in line 25, so obviously it is insisting on adding it, but there is no such column in the database.

 

Marianne

Link to comment
Share on other sites

  • 1 year later...
  • 10 months later...

Just tried this contribution out and one column modification is missing in the package.

 

If you get the mfg_abbrev missing error just run the following code in phpmyadmin:

 

ALTER TABLE manufacturers ADD mfg_abbrev VARCHAR(10)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...