Jump to content
Sign in to follow this  
iiinetworks

[CONTRIBUTION] File uploads as an Option Feature

Recommended Posts

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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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 ....

Share this post


Link to post
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.

Share this post


Link to post
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;

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Try

$products_name .= '<br>' . tep_image($products[$i][$option]['products_options_values_name'], $products[$i][$option]['products_options_values_name'], 5, 5)  . '<br>';

Hth,

Matt


Always back up before making changes.

Share this post


Link to post
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 .......

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Hi Matt, I was wondering is it possible to limit the size of the image that could be uploaded, since I dont want people uploading files bigger than 5 MB ....

 

THanks

Share this post


Link to post
Share on other sites

There is a max file size setting for PHP. The actual name is posted earlier in this thread.

 

Hth,

Matt


Always back up before making changes.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Eyal,

 

I tried three different times and it worked for me every time. Have you tried any other browsers or internet connections? Not sure what would cause that.

 

Hth,

Matt


Always back up before making changes.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×