petsk Posted June 2, 2015 Share Posted June 2, 2015 How can I get the upload class to loop through several uploaded files? If I change an upload field to this, so that many files can be selected at once: tep_draw_file_field('manufacturers_image[]', '', ' multiple="multiple"'); But how do I add the foreach loop with the example below? $manufacturers_image = new upload('manufacturers_image[]'); $manufacturers_image->set_destination(DIR_FS_CATALOG_IMAGES); if ($manufacturers_image->parse() && $manufacturers_image->save()) { tep_db_query("update " . TABLE_MANUFACTURERS . " set manufacturers_image = '" . tep_db_input($manufacturers_image->filename) . "' where manufacturers_id = '" . (int)$manufacturers_id . "'"); } Link to comment Share on other sites More sharing options...
tgely Posted June 2, 2015 Share Posted June 2, 2015 Hi, you are running conflict with upload class. Class has only one file handler at this moment. Multiply files not be able to counted for upload. if you would like to use oscommerce one file upload class than you should look after categories.php where post file array by names are for upload. Here is an exampe: foreach ($HTTP_POST_FILES as $key => $value) { // Update existing large product images if (preg_match('/^products_image_large_([0-9]+)$/', $key, $matches)) { $pi_sort_order++; $sql_data_array = array('htmlcontent' => tep_db_prepare_input($HTTP_POST_VARS['products_image_htmlcontent_' . $matches[1]]), 'sort_order' => $pi_sort_order); $t = new upload($key); $t->set_destination(DIR_FS_CATALOG_IMAGES); if ($t->parse() && $t->save()) { $sql_data_array['image'] = tep_db_prepare_input($t->filename); } tep_db_perform(TABLE_PRODUCTS_IMAGES, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "' and id = '" . (int)$matches[1] . "'"); $piArray[] = (int)$matches[1]; } elseif (preg_match('/^products_image_large_new_([0-9]+)$/', $key, $matches)) { // Insert new large product images $sql_data_array = array('products_id' => (int)$products_id, 'htmlcontent' => tep_db_prepare_input($HTTP_POST_VARS['products_image_htmlcontent_new_' . $matches[1]])); $t = new upload($key); $t->set_destination(DIR_FS_CATALOG_IMAGES); if ($t->parse() && $t->save()) { $pi_sort_order++; $sql_data_array['image'] = tep_db_prepare_input($t->filename); $sql_data_array['sort_order'] = $pi_sort_order; tep_db_perform(TABLE_PRODUCTS_IMAGES, $sql_data_array); $piArray[] = tep_db_insert_id(); } } } I hope this will help. osCommerce based shop owner with minimal design and focused on background works. When the less is more.Email managment with tracking pixel, package managment for shipping, stock management, warehouse managment with bar code reader, parcel shops management on 3000 pickup points without local store. Link to comment Share on other sites More sharing options...
petsk Posted June 2, 2015 Author Share Posted June 2, 2015 I don't quite understand what you mean? The following piece of code works fine, using two input fields. Why can't the two fields be replaced with a single 'multiple' field? tep_draw_file_field('popup_images_1') tep_draw_file_field('popup_images_2') for ($i = 1; $i <= 2; $i++) { if (is_uploaded_file($HTTP_POST_FILES['popup_images_' . $i]['tmp_name'])) { $products_image = new upload('popup_images_' . $i); $products_image->set_destination(DIR_FS_CATALOG_IMAGES); if ($products_image->parse() && $products_image->save()) { $products_image_name = $products_image->filename; echo 'Working fine!'; } } } Link to comment Share on other sites More sharing options...
tgely Posted June 2, 2015 Share Posted June 2, 2015 http://php.net/manual/en/reserved.variables.files.php osCommerce based shop owner with minimal design and focused on background works. When the less is more.Email managment with tracking pixel, package managment for shipping, stock management, warehouse managment with bar code reader, parcel shops management on 3000 pickup points without local store. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.