Guest Posted December 5, 2003 Share Posted December 5, 2003 This code allows one to do three things: 1. Change the filename of an image at time of upload. 2. Put the image in a subdirectory of images/ 3. Change the product or category image location in the database without uploading a new image. If the image name is blank and none is uploaded, then it will erase the image. In admin/categories.php, around lines 80-2, change from if ($categories_image = new upload('categories_image', DIR_FS_CATALOG_IMAGES)) { tep_db_query("update " . TABLE_CATEGORIES . " set categories_image = '" . tep_db_input($categories_image->filename) . "' where categories_id = '" . (int)$categories_id . "'"); } to $categories_image = new upload('categories_image'); $categories_image_name = ''; if (isset($HTTP_POST_VARS['image_destination']) && tep_not_null($HTTP_POST_VARS['image_destination'])) { $categories_image->set_destination(dirname(DIR_FS_CATALOG_IMAGES . $HTTP_POST_VARS['image_destination'])); $categories_image_name = $HTTP_POST_VARS['image_destination']; } else { $categories_image->set_destination(DIR_FS_CATALOG_IMAGES); } if ($categories_image->parse()) { if (isset($HTTP_POST_VARS['image_destination']) && tep_not_null($HTTP_POST_VARS['image_destination'])) { $categories_image->set_filename(basename(DIR_FS_CATALOG_IMAGES . $HTTP_POST_VARS['image_destination'])); } if ($categories_image->save()) { $categories_image_name = $categories_image->filename; } } if (isset($HTTP_POST_VARS['image_destination']) && tep_not_null($HTTP_POST_VARS['image_destination'])) { $categories_image_name = $HTTP_POST_VARS['image_destination']; } tep_db_query("update " . TABLE_CATEGORIES . " set categories_image = '" . tep_db_input($categories_image_name) . "' where categories_id = '" . (int)$categories_id . "'"); Around lines 224-6, change from if (isset($HTTP_POST_VARS['products_image']) && tep_not_null($HTTP_POST_VARS['products_image']) && ($HTTP_POST_VARS['products_image'] != 'none')) { $sql_data_array['products_image'] = tep_db_prepare_input($HTTP_POST_VARS['products_image']); } to $sql_data_array['products_image'] = tep_db_prepare_input($HTTP_POST_VARS['products_image']); Around lines 315-20, change from $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($HTTP_POST_VARS['products_previous_image']) ? $HTTP_POST_VARS['products_previous_image'] : ''); } to if (isset($HTTP_POST_VARS['image_destination'])) { $products_image->set_destination(dirname(DIR_FS_CATALOG_IMAGES . $HTTP_POST_VARS['image_destination'])); $products_image->set_filename(basename(DIR_FS_CATALOG_IMAGES . $HTTP_POST_VARS['image_destination'])); } else { $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 = ''; } if (isset($HTTP_POST_VARS['image_destination'])) { $products_image_name = $HTTP_POST_VARS['image_destination']; } Around lines 562-5, change from <tr> <td class="main"><?php echo TEXT_PRODUCTS_IMAGE; ?></td> <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_file_field('products_image') . '<br>' . tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . $pInfo->products_image . tep_draw_hidden_field('products_previous_image', $pInfo->products_image); ?></td> </tr> to <tr> <td class="main"><?php echo TEXT_PRODUCTS_IMAGE; ?></td> <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_file_field('products_image'); ?></td> </tr> <tr> <td class="main"><?php echo TEXT_PRODUCTS_IMAGE_DESTINATION; ?></td> <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_input_field('image_destination', $pInfo->products_image); ?></td> </tr> Around line 887, change from $contents[] = array('text' => '<br>' . TEXT_CATEGORIES_IMAGE . '<br>' . tep_draw_file_field('categories_image')); to $contents[] = array('text' => '<br>' . TEXT_CATEGORIES_IMAGE . '<br>' . tep_draw_file_field('categories_image')); $contents[] = array('text' => '<br>' . TEXT_CATEGORIES_IMAGE_DESTINATION . '<br>' . tep_draw_input_field('image_destination')); Around line 905, change from $contents[] = array('text' => '<br>' . TEXT_EDIT_CATEGORIES_IMAGE . '<br>' . tep_draw_file_field('categories_image')); to $contents[] = array('text' => '<br>' . TEXT_EDIT_CATEGORIES_IMAGE . '<br>' . tep_draw_file_field('categories_image')); $contents[] = array('text' => '<br>' . TEXT_CATEGORIES_IMAGE_DESTINATION . '<br>' . tep_draw_input_field('image_destination', $cInfo->categories_image)); In admin/includes/languages/english/categories.php (or whatever language), add something like define('TEXT_CATEGORIES_IMAGE_DESTINATION', 'File location in the images directory: '); define('TEXT_PRODUCTS_IMAGE_DESTINATION', 'File location in the images directory: '); Hth, Matt Link to comment Share on other sites More sharing options...
natophonic Posted December 10, 2003 Share Posted December 10, 2003 Matt, ***THANK YOU!!!*** i was about to go mad trying to modify the image path on about 35 product accessories i'm adding today! phpmyadmin is ok, but a real application-specific GUI is better. :) i made one change, which works when you're changing the image from something pre-existing, and using the upload function: from ? ? ? ?if (isset($HTTP_POST_VARS['image_destination'])) { ? ? ? ? ?$products_image->set_destination(dirname(DIR_FS_CATALOG_IMAGES . $HTTP_POST_VARS['image_destination'])); ? ? ? ? ?$products_image->set_filename(basename(DIR_FS_CATALOG_IMAGES . $HTTP_POST_VARS['image_destination'])); ? ? ? ?} else { ? ? ? ? ?$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 = ''; ? ? ? ?} ? ? ? ?if (isset($HTTP_POST_VARS['image_destination'])) { ? ? ? ? ?$products_image_name = $HTTP_POST_VARS['image_destination']; ? ? ? ?} to if (isset($HTTP_POST_VARS['image_destination'])) { $products_image->set_destination(dirname(DIR_FS_CATALOG_IMAGES . $HTTP_POST_VARS['image_destination'])); $products_image->set_filename(basename(DIR_FS_CATALOG_IMAGES . $HTTP_POST_VARS['image_destination'])); } else { $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 = ''; if (isset($HTTP_POST_VARS['image_destination'])) { $products_image_name = $HTTP_POST_VARS['image_destination']; } } thanks again... it'd be great if this functionality made it into the main OSC code base! Link to comment Share on other sites More sharing options...
Guest Posted December 12, 2003 Share Posted December 12, 2003 Hello Matt Is it possible to add this code to the Ultimate Images pack contribution? Thanks, Jiten Link to comment Share on other sites More sharing options...
Druide Posted December 12, 2003 Share Posted December 12, 2003 GREAT WORK ! But why is it needed to delete all the lines with: 'products_previous_image' this will cause some trouble with lots of people who have installed contributions who use this information. I've got my shop too much adjusted to tell you which contributions...lol But still its a GREAT tip that NEEDS to be added to the core of OSC MS3 Robert We all need to learn it once, how hard it may seem when you look at it, also you will master it someday ;) Link to comment Share on other sites More sharing options...
Druide Posted December 12, 2003 Share Posted December 12, 2003 i've just created an addon that CREATES your new directory on the fly, and the nice thing about it is that is also CHMOD 777 so writable :):) I'll post it soon, just be patient Robert We all need to learn it once, how hard it may seem when you look at it, also you will master it someday ;) Link to comment Share on other sites More sharing options...
Guest Posted December 12, 2003 Share Posted December 12, 2003 But why is it needed to delete all the lines with: 'products_previous_image'It moves products_previous_image into the new text box. Perhaps you could get the effect that you want by replacing 'image_destination' with 'products_previous_image' everywhere it appears? Not very descriptive of what it is actually doing but might improve contribution compatibility for you. Hth, Matt Link to comment Share on other sites More sharing options...
Druide Posted December 13, 2003 Share Posted December 13, 2003 As ALWAYS BACKUP !!! BACKUP !!! BACKUP !!! BACKUP !!! BACKUP !!! BACKUP !!! BACKUP !!! BACKUP !!! BACKUP !!! BACKUP !!! BACKUP !!! BACKUP !!! BACKUP !!! BACKUP !!! In admin/categories.php Around lines 315-20, change from ? ? ? ?$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($HTTP_POST_VARS['products_previous_image']) ? $HTTP_POST_VARS['products_previous_image'] : ''); ? ? ? ?} to ? ? ? ?if (isset($HTTP_POST_VARS['image_destination'])) { ? ? ? ? ?$products_image->set_destination(dirname(DIR_FS_CATALOG_IMAGES . $HTTP_POST_VARS['image_destination'])); ? ? ? ? ?$products_image->set_filename(basename(DIR_FS_CATALOG_IMAGES . $HTTP_POST_VARS['image_destination'])); ? ? ? ?} else { ? ? ? ? ?$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 = ''; ? ? ? ?} ? ? ? ?if (isset($HTTP_POST_VARS['image_destination'])) { ? ? ? ? ?$products_image_name = $HTTP_POST_VARS['image_destination']; ? ? ? ?} a little ADDON to this (took me all day to make it work in OSC...lol) What does it do ? Well this little ADDON creates for you a new directory ON_THE_FLY and then uploads the image into it. So you Dont need to create a new directory with your FTP client and then change it to CHMOD 777, and you know why ? This little tool does it ALL for you Cool or not, i think its AWESOME :):) I had an idea again and started to work on it and VOILA i made it work, this can be used also for those error 'not writable directories' messages that you get after you do a clean OSC installation (for experts ONLY ;) ) In admin/categories.php Around lines 315-20, change from $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($HTTP_POST_VARS['products_previous_image']) ? $HTTP_POST_VARS['products_previous_image'] : ''); } to (this BLOCK has been changed by Robert Hellemans) if (isset($HTTP_POST_VARS['image_destination'])) { // BOF ftpmkdir by robert hellemans // split the 'new' directory and file from eachother $image_destination_dir = explode("/" , $HTTP_POST_VARS['image_destination']); // check if the 'new' catalog image directory exists if (is_dir(DIR_FS_CATALOG_IMAGES . $image_destination_dir[0])) { // uncomment the next line if you want to debug // $messageStack->add(DIR_WS_IMAGES . $image_destination_dir[0] . " already exists", 'caution'); } else { include(DIR_WS_INCLUDES . 'ftpmkdir.php'); FtpMkdir(DIR_FTP_MKDIR, $image_destination_dir[0]); if (!is_writeable(DIR_FS_CATALOG_IMAGES . $image_destination_dir[0])) $messageStack->add(DIR_WS_IMAGES . $image_destination_all[0] . " is NOT writable", 'error'); if (is_writeable(DIR_FS_CATALOG_IMAGES . $image_destination_dir[0])) $messageStack->add("Success: Directory " . DIR_WS_IMAGES . $image_destination_all[0] . " is created & CHMOD 777", 'success'); } // EOF ftpmkdir $products_image->set_destination(dirname(DIR_FS_CATALOG_IMAGES . $HTTP_POST_VARS['image_destination'])); $products_image->set_filename(basename(DIR_FS_CATALOG_IMAGES . $HTTP_POST_VARS['image_destination'])); } else { $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 = ''; } if (isset($HTTP_POST_VARS['image_destination'])) { $products_image_name = $HTTP_POST_VARS['image_destination']; } add in admin/includes/configure.php // define your ftp connection define('FTP_SERVER', '12.34.567.890'); // FTP server IP, same info as you use to upload by a FTP client define('FTP_SERVER_USERNAME', 'login'); // same login info as you use to upload by a FTP client define('FTP_SERVER_PASSWORD', 'password'); // same password as you use to upload by a FTP client define('DIR_FTP_MKDIR', '/httpdocs/catalog/images'); // login by your FTP client to see the path you need create a new file and call it: ftpmkdir.php put this code block into the file and save it, then upload it to your admin/includes/ftpmkdir.php <?php /* Created by Robert Hellemans with information from php dot net ftpmkdir.php 12 Dec 2003 Robert Hellemans webmaster at RuddlesMills dot com Feel FREE to use this file but leave my information in it Thank you */ // create directory through FTP connection function FtpMkdir($path, $newDir) { $connection = ftp_connect(FTP_SERVER); // connection $result = ftp_login($connection, FTP_SERVER_USERNAME, FTP_SERVER_PASSWORD); // login to ftp server // check if connection was made if ((!$connection) || (!$result)) { return false; exit(); } else { ftp_chdir($connection, $path); // go to destination dir if(ftp_mkdir($connection,$newDir)) { // create directory ftp_site($connection, "CHMOD 777 $path/$newDir") or die("FTP SITE CMD failed."); return $newDir; } else { return false; } ftp_close($conn_id); // close connection } } ?> Robert We all need to learn it once, how hard it may seem when you look at it, also you will master it someday ;) Link to comment Share on other sites More sharing options...
djgizmo Posted December 13, 2003 Share Posted December 13, 2003 I too used this. I think its EXCELENT! I too had many pics on the server already and could not properly link them w/o using myPHPadmin till this change came around. I vote to impliment it DIRECTLY into the next release of oscommerce. Thank you all Sean Link to comment Share on other sites More sharing options...
inetchoices Posted December 13, 2003 Share Posted December 13, 2003 Ok fellas: For the php challenged, could one of you please explain to me in which order these changes should be applied? I see three mods here. Are they all the same thing? I did the first one... no problems. Added the second one and had a parse error I could not get rid of. So I put my backup original back into /admin and will wait until some nice person tells this non-coder what goes where - when and which code is and isn't necessary with respect to the three mods in this thread. Thanks :-) Khim~ PS: Could some nice person who has the knowledge wrap this up and add it as a contrib? Do not meddle in the affairs of Dragons, for you are crunchy and good with ketchup :-) Link to comment Share on other sites More sharing options...
Druide Posted December 14, 2003 Share Posted December 14, 2003 I have made it a contribution (Matt's code and mine) no offence to nathan moser but i thought to keep it usable for new installations, since OSC MS3 is coming SOON :):) you can find it at http://www.oscommerce.com/forums/index.php?act=ST&f=7&t=70174 for further development since this is not the right forum for it ;) Robert We all need to learn it once, how hard it may seem when you look at it, also you will master it someday ;) Link to comment Share on other sites More sharing options...
Genius Posted March 12, 2004 Share Posted March 12, 2004 Please Help, I have been having trouble trying to upload images... when i type the image directory image name or the image name directly Sometime the image shows but then the image size becomes 0 and i loose the image... I have tried to this contribution but still no joy please could someone assist Link to comment Share on other sites More sharing options...
♥ecartz Posted August 21, 2009 Share Posted August 21, 2009 Updated for RC2a: In admin/categories.php, around lines 80-85, change from $categories_image = new upload('categories_image'); $categories_image->set_destination(DIR_FS_CATALOG_IMAGES); if ($categories_image->parse() && $categories_image->save()) { tep_db_query("update " . TABLE_CATEGORIES . " set categories_image = '" . tep_db_input($categories_image->filename) . "' where categories_id = '" . (int)$categories_id . "'"); } to $categories_image = new upload('categories_image'); $categories_image_name = ''; if (isset($HTTP_POST_VARS['image_destination']) && tep_not_null($HTTP_POST_VARS['image_destination'])) { $categories_image->set_destination(dirname(DIR_FS_CATALOG_IMAGES . $HTTP_POST_VARS['image_destination'])); $categories_image_name = $HTTP_POST_VARS['image_destination']; } else { $categories_image->set_destination(DIR_FS_CATALOG_IMAGES); } if ($categories_image->parse()) { if (isset($HTTP_POST_VARS['image_destination']) && tep_not_null($HTTP_POST_VARS['image_destination'])) { $categories_image->set_filename(basename(DIR_FS_CATALOG_IMAGES . $HTTP_POST_VARS['image_destination'])); } if ($categories_image->save()) { $categories_image_name = $categories_image->filename; } } if (isset($HTTP_POST_VARS['image_destination']) && tep_not_null($HTTP_POST_VARS['image_destination'])) { $categories_image_name = $HTTP_POST_VARS['image_destination']; } tep_db_query("update " . TABLE_CATEGORIES . " set categories_image = '" . tep_db_input($categories_image_name) . "' where categories_id = '" . (int)$categories_id . "'"); Around lines 227-229, change from if (isset($HTTP_POST_VARS['products_image']) && tep_not_null($HTTP_POST_VARS['products_image']) && ($HTTP_POST_VARS['products_image'] != 'none')) { $sql_data_array['products_image'] = tep_db_prepare_input($HTTP_POST_VARS['products_image']); } to $sql_data_array['products_image'] = tep_db_prepare_input($HTTP_POST_VARS['products_image']); Around lines 318-323, change from $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($HTTP_POST_VARS['products_previous_image']) ? $HTTP_POST_VARS['products_previous_image'] : ''); } to if (isset($HTTP_POST_VARS['image_destination'])) { $products_image->set_destination(dirname(DIR_FS_CATALOG_IMAGES . $HTTP_POST_VARS['image_destination'])); $products_image->set_filename(basename(DIR_FS_CATALOG_IMAGES . $HTTP_POST_VARS['image_destination'])); } else { $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 = ''; } if (isset($HTTP_POST_VARS['image_destination'])) { $products_image_name = $HTTP_POST_VARS['image_destination']; } Around lines 565-568, change from <tr> <td class="main"><?php echo TEXT_PRODUCTS_IMAGE; ?></td> <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_file_field('products_image') . '<br>' . tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . $pInfo->products_image . tep_draw_hidden_field('products_previous_image', $pInfo->products_image); ?></td> </tr> to <tr> <td class="main"><?php echo TEXT_PRODUCTS_IMAGE; ?></td> <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_file_field('products_image'); ?></td> </tr> <tr> <td class="main"><?php echo TEXT_PRODUCTS_IMAGE_DESTINATION; ?></td> <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_input_field('image_destination', $pInfo->products_image); ?></td> </tr> Around line 890, change from $contents[] = array('text' => '<br>' . TEXT_CATEGORIES_IMAGE . '<br>' . tep_draw_file_field('categories_image')); to $contents[] = array('text' => '<br>' . TEXT_CATEGORIES_IMAGE . '<br>' . tep_draw_file_field('categories_image')); $contents[] = array('text' => '<br>' . TEXT_CATEGORIES_IMAGE_DESTINATION . '<br>' . tep_draw_input_field('image_destination')); Around line 908, change from $contents[] = array('text' => '<br>' . TEXT_EDIT_CATEGORIES_IMAGE . '<br>' . tep_draw_file_field('categories_image')); to $contents[] = array('text' => '<br>' . TEXT_EDIT_CATEGORIES_IMAGE . '<br>' . tep_draw_file_field('categories_image')); $contents[] = array('text' => '<br>' . TEXT_CATEGORIES_IMAGE_DESTINATION . '<br>' . tep_draw_input_field('image_destination', $cInfo->categories_image)); In admin/includes/languages/english/categories.php (or whatever language), add something like define('TEXT_CATEGORIES_IMAGE_DESTINATION', 'File location in the images directory: '); define('TEXT_PRODUCTS_IMAGE_DESTINATION', 'File location in the images directory: '); Always back up before making changes. Link to comment Share on other sites More sharing options...
Guest Posted September 21, 2009 Share Posted September 21, 2009 I have made it a contribution (Matt's code and mine) no offence to nathan moser but i thought to keep it usable for new installations, since OSC MS3 is coming SOON :):) Interesting comment. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.