Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

[CONTRIBUTION] File uploads as an Option Feature


Guest

Recommended Posts

  • Replies 482
  • Created
  • Last Reply

Top Posters In This Topic

Hi Matt, can you please guide me ... This is in reference to the upload feature 0.7, actually I am trying to display the image thats being uploaded, I am not sure which files are involved that has to be changed and do you think this would require a lot of change in code .... since I am relatively new with PHP so I am not sure ....

 

Thanks for your help ....

Link to comment
Share on other sites

You would make the changes in the .htaccess file in images/upload (to allow images to be viewed), the shopping_cart.php file (to display the image), and possibly includes/application_top.php (you need to save the extension so the browser knows how to display the image).

 

Make sure that you have the includes/classes/upload.php file set to restrict uploads to image extensions as well. Wouldn't want someone to access a PHP file that they uploaded.

 

Hth,

Matt

Always back up before making changes.

Link to comment
Share on other sites

Hi Matt, I added the above line in the shoppingcart.php to view the uploaded image ...

$products_name .= '<br><img src="images/uploads/' . $products[$i][$option]['products_options_values_name'] . '" border=0><br>';

 

this line was added after

 

if (isset($products[$i]['attributes']) && is_array($products[$i]['attributes'])) {

        reset($products[$i]['attributes']);

        while (list($option, $value) = each($products[$i]['attributes'])) {

          $products_name .= '<br><small><i> - ' . $products[$i][$option]['products_options_name'] . ' ' . $products[$i][$option]['products_options_values_name'] . '</i></small>';

 

but its giving me a box with the broken image ... what am I doing wrong ...

 

You can view the site at MosaicArtKeepsakes

 

Thanks

 

Ali

Edited by aliharis2004
Link to comment
Share on other sites

Please correct me if I am wrong, in ref. to my earlier message .... is it because since the name of the image is being changed when its uploaded and its looking for the orignal name of the image .. if thats the problem, how can I work around it ..... thanks for your help ....

Link to comment
Share on other sites

What do the changes in includes/application_top.php look like in your store? You basically need to change the filename to match the attribute value (it is actually looking for "12. image.ext" rather than the original image.ext name). You should be able to set them to match in includes/application_top.php. The only thing that might concern me is the space between 12. and image.ext. Some filesystems can be goofy about spaces.

 

Hth,

Matt

Always back up before making changes.

Link to comment
Share on other sites

Hi Matt, the application_top.php looks something like this, I didnt make any changes to what u have for the upload feature, what do I need to do to fix the problem ... thanks :

 

// iii 030813 added: File uploading: save uploaded files with unique file names

          $real_ids = $HTTP_POST_VARS['id'];

          if ($HTTP_POST_VARS['number_of_uploads'] > 0) {

            require(DIR_WS_CLASSES . 'upload.php');

            for ($i = 1; $i <= $HTTP_POST_VARS['number_of_uploads']; $i++) {

              if (tep_not_null($_FILES['id']['tmp_name'][TEXT_PREFIX . $HTTP_POST_VARS[uPLOAD_PREFIX . $i]]) and ($_FILES['id']['tmp_name'][TEXT_PREFIX . $HTTP_POST_VARS[uPLOAD_PREFIX . $i]] != 'none')) {

                $products_options_file = new upload('id');

                $products_options_file->set_destination(DIR_FS_UPLOADS);

                if ($products_options_file->parse(TEXT_PREFIX . $HTTP_POST_VARS[uPLOAD_PREFIX . $i])) {

                  if (tep_session_is_registered('customer_id')) {

                    tep_db_query("insert into " . TABLE_FILES_UPLOADED . " (sesskey, customers_id, files_uploaded_name) values('" . tep_session_id() . "', '" . $customer_id . "', '" . tep_db_input($products_options_file->filename) . "')");

                  } else {

                    tep_db_query("insert into " . TABLE_FILES_UPLOADED . " (sesskey, files_uploaded_name) values('" . tep_session_id() . "', '" . tep_db_input($products_options_file->filename) . "')");

                  }

                  $insert_id = tep_db_insert_id();

                  $real_ids[TEXT_PREFIX . $HTTP_POST_VARS[uPLOAD_PREFIX . $i]] = $insert_id . ". " . $products_options_file->filename;

                  $products_options_file->set_filename("$insert_id" . $products_options_file->filename);

                  if (!($products_options_file->save())) {

                    break 2;

                  }

                } else {

                  break 2;

                }

              } else { // No file uploaded -- use previous value

                $real_ids[TEXT_PREFIX . $HTTP_POST_VARS[uPLOAD_PREFIX . $i]] = $HTTP_POST_VARS[TEXT_PREFIX . UPLOAD_PREFIX . $i];

              }

            }

          }

          $cart->add_cart($HTTP_POST_VARS['products_id'], $cart->get_quantity(tep_get_uprid($HTTP_POST_VARS['products_id'], $real_ids))+1, $real_ids);

// iii 030813 end of changes.

        }

        tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));

        break;

Link to comment
Share on other sites

I would try changing

                  $products_options_file->set_filename("$insert_id" . $products_options_file->filename);

to

                  $products_options_file->set_filename("$insert_id" . '. ' . $products_options_file->filename);

If that doesn't work, try changing both

                  $real_ids[TEXT_PREFIX . $HTTP_POST_VARS[UPLOAD_PREFIX . $i]] = $insert_id . ". " . $products_options_file->filename;
                 $products_options_file->set_filename("$insert_id" . $products_options_file->filename);

to

                  $real_ids[TEXT_PREFIX . $HTTP_POST_VARS[UPLOAD_PREFIX . $i]] = "$insert_id" . '.' . $products_options_file->filename;
                 $products_options_file->set_filename("$insert_id" . '.' . $products_options_file->filename);

Hth,

Matt

Always back up before making changes.

Link to comment
Share on other sites

Hi Matt, Right now the image that gets uploaded shows up of the same size as it is ... I was wondering is it possible to specify a certain size of the image e.g. 5x5... I tried changing the following cdfes ..

 

$products_name .= '<br><img src="images/uploads/' . $products[$i][$option]['products_options_values_name'] . '" border=0><br>';

 

but it keeps giving Parsing #rror ..

Edited by aliharis2004
Link to comment
Share on other sites

Hi Matt, its coming up with broken image, since its looking for the image in the

 

/catalog/36.%20b3.gif

 

rather than in

 

/catalog/images/uploads/36.%20b3.gif

 

After I changed the code to:

 

$products_name .= '<br><img src="images/uploads/' . tep_image($products[$i][$option]['products_options_values_name'], $products[$i][$option]['products_options_values_name'], 50, 50) . '"<br>';

 

the path of the image its showing is :

 

/catalog/images/uploads/%3Cimg%20src=

 

What am I doing wrong ? Thanks .......

Link to comment
Share on other sites

What am I doing wrong ? Thanks .......
Following my instructions apparently...
$products_name .= '<br>' . tep_image(DIR_WS_UPLOADS . $products[$i][$option]['products_options_values_name'], $products[$i][$option]['products_options_values_name'], 5, 5)  . '<br>';

I remember thinking that it would need DIR_WS_UPLOADS there, but apparently I forgot to actually write it that way.

 

Sorry,

Matt

Always back up before making changes.

Link to comment
Share on other sites

Hi,

 

I started today installing the Contribution on OSC 2.2MS2 but I have some trouble importing the sql-file 'option_type_feature.sql' via PHPMyAdmin. While importing this line

 

INSERT INTO `configuration` ( `configuration_id` , `configuration_title` , `configuration_key` , `configuration_value` , `configuration_description` , `configuration_group_id` , `sort_order` , `last_modified` , `date_added` , `use_function` , `set_function` )

VALUES ( 169, 'Product option type Select', 'PRODUCTS_OPTIONS_TYPE_SELECT', '0', 'The number representing the Select type of product option.', 0, NULL , now( ) , now( ) , NULL , NULL )

 

and the follwing two lines I'm getting the error

 

"Duplicate entry '169' for key 1"

 

I don't know what to do to solve the problem, anyone knows a solution?

 

Thanks a lot for help,

Karsten

Link to comment
Share on other sites

Karsten,

 

Try

INSERT INTO `configuration` ( `configuration_title` , `configuration_key` , `configuration_value` , `configuration_description` , `configuration_group_id` , `sort_order` , `last_modified` , `date_added` , `use_function` , `set_function` ) 
VALUES ( 'Product option type Select', 'PRODUCTS_OPTIONS_TYPE_SELECT', '0', 'The number representing the Select type of product option.', 0, NULL , now( ) , now( ) , NULL , NULL )

instead. also remove 'configuration_id' and the associated number in VALUES for the other lines as well.

 

Hth,

Matt

Always back up before making changes.

Link to comment
Share on other sites

  • 1 month later...

Dear Matt,

 

First of all, thank you so much for this great contribution !

 

I've installed the latest version and it works great, but I've encountered a strange thing:

 

When I press the 'Add to cart' button and the file is being uploaded, just after it has been uploaded I get a 'Cannot find server' error, and the url in the browser is: 'http://just4u.co.il/product_info.php?products_id=29&action=add_product&osCsid=65437da70fbe0eb77b17eebb9d39c1c7'. However, when I press reload, I can see the 'product_info.php' page properly and I can continue the checkout process.

 

This problem happens most of the times, though not all the times. I remember 3 or 4 times that it went flawlessly.

 

Just to mention that I'm behind a NAPT router, I don't know if it has something to do with it, but who knows..

 

Your help will be really appreciated. If you are trying to access my site, please use test:test ad user:pass.

 

Thanks in advance for your help..

 

Best Wishes,

Eyal Moshe

Link to comment
Share on other sites

Matt,

 

I'll try it from other internet connections and I'll see. If none of the contribution's users has encountered this problem, I guess it has to do something with my provider.

 

Thanks,

Eyal

Link to comment
Share on other sites

  • 2 weeks later...
i like to have the filesize-check as a part of the upload-class. so if a user wants to uplaod a too big file a messages_stack "error: file too big" occurs..
In product_info.php
        <td class="main"><input type="file" name="id[<?php echo TEXT_PREFIX . $products_options_name['products_options_id']; ?>]"><br><?php echo $cart->contents[$HTTP_GET_VARS['products_id']]['attributes_values'][$products_options_name['products_options_id']] . tep_draw_hidden_field(UPLOAD_PREFIX . $number_of_uploads, $products_options_name['products_options_id']) . tep_draw_hidden_field(TEXT_PREFIX . UPLOAD_PREFIX . $number_of_uploads, $cart->contents[$HTTP_GET_VARS['products_id']]['attributes_values'][$products_options_name['products_options_id']]); ?></td>

change to

        <td class="main">
         <?php echo if ($number_of_uploads == 1) tep_draw_hidden_field('MAX_FILE_SIZE', UPLOAD_MAX_FILE_SIZE); ?>
         <input type="file" name="id[<?php echo TEXT_PREFIX . $products_options_name['products_options_id']; ?>]"><br>
         <?php echo
$cart->contents[$HTTP_GET_VARS['products_id']]['attributes_values'][$products_options_name['products_options_id']] . 
                 tep_draw_hidden_field(UPLOAD_PREFIX . $number_of_uploads, $products_options_name['products_options_id']) .
                 tep_draw_hidden_field(TEXT_PREFIX . UPLOAD_PREFIX . $number_of_uploads,
$cart->contents[$HTTP_GET_VARS['products_id']]['attributes_values'][$products_options_name['products_options_id']]); ?>
       </td>

You still won't get the message stack error, but it should give an error prior to upload.

 

Hth,

Matt

Always back up before making changes.

Link to comment
Share on other sites

Hi All,

 

Although not directly related to this contribution, I was just curious if someone has resolved the 32 bytes limit of the products_text attribute option. I would like to have a text box and get from my customers much longer texts (300-400 bytes) so if someone has already done that, I'll be happy to hear how..

 

Thanks in advance,

Eyal Moshe

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...