Jump to content
  • Checkout
  • Login
  • Get in touch


The e-commerce.

populate hidden field from another form field on submit - (for image resize function)


Recommended Posts

Hi all,


I have a heavily modified OSC site so most image re-size contributions won't work out of the box.


I allow customers to upload products (mp3 recordings) and would like to generate three 'Album Art' image sizes when they submit only 1 master image via the products submit form.


I have downloaded a great contribution (addons.oscommerce.com/info/5555) by Snowbird that modifies includes/classes/upload.php to re-size the 'Album Art' photo on the submit action. It works brilliantly (it has dimension ratio locking and file type confirmation).


Problem is that I need three different image sizes and I only want my customers to have to point at one master image. Snowbird's script only returns one re-sized image to be uploaded.


I've looked extensively at the myriad of thumbnail generators and re-size contributions but due to the nature of my modified code Snowbird's simple function seems to be best for me.


I made three slight variations of his upload.php and saved each under different names (ie upload350.php) to mark which functions generate the desired image dimensions. All three functions have been referenced, manually code tested and work perfectly on my site.


So - being the newb I am - I'd like some help mirroring one form field 'image' into two additional(hidden)fields for a total of three unique fields and 'upload' functions. I've been trying with just two fields/functions to start with and have been unsuccessful so far.


I'm guessing I need hidden fields so that I can discretely take the data from my actual 'image' field and process it separately???


Here's my 'Album Art' form code:


<?php // Draw the field for the Album Art Photo> ?>

<span class="main"><?php echo tep_draw_file_field('collection_large_image') ; ?></span></p>



<?php // Draw the field for the Album Art Thumbnail Photo> ?>

<span class="main"><?php echo tep_draw_hidden_field('collection_thumbnail_image'); ?></span></p>



The idea is to get the 'collection_large_image' data and pass it to the 'collection_thumbnail_image' so that both can be processed as separate fields but I don't know how to do that in this case.


My thinking is that if I can mirror the field data I can run the following two uploads correctly:



//Resize and Upload the 'Album Art' Large Image

if ($collection_large_image = new upload350('collection_large_image', 'images/artists'))





$collection_file_name = $collection_large_image->filename;



//Upload SQL

tep_db_query("update " . TABLE_PRODUCTS . " set products_mediumimage = '" . $collection_file_name . "' where products_id = '" . $products_id . "'");



//Resize and Upload the 'Album Art' Thumbnail Image

if ($collection_thumbnail_image = new upload100('collection_thumbnail_image', 'images/artists'))




$collection_thumbnail_file_name = $collection_thumbnail_image->filename;


//Upload SQL

tep_db_query("update " . TABLE_PRODUCTS . " set products_image = '" . $collection_thumbnail_file_name . "' where products_id = '" . $products_id . "'");

} ?>



So I am wondering - could this work? Are my expressions correct? How I can get the hidden field data correct so that the upload100 function works when the submit button is hit? One last worry - Even if I can use the same path/filename for both field updates - will it crash because of duplicate filenames uploading to the same destination folder? My upload functions all add year/month/day/ (and I think minute,second) strings to the filenames but I'm not sure how the two files will be named if submitted at the exact same moment in time.


Thanks so much for any time and assistance you can give. This one has me going bonkers...



Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...