Jump to content
Sign in to follow this  
iiinetworks

[CONTRIBUTION] File uploads as an Option Feature

Recommended Posts

I have recently moved my website to a different server.

 

Now when I try to upload a file using the upload feature I get the error message

Error: destination (/usr/local/bin/images/uploads/) does not exist.

 

I can't find anything in my scripts pointing to /usr/local/bin/. The folders images/uploads do exist.

 

Can anyone advise where I should be looking to correct the problem, perhaps in the configuration? The site is working correctly otherwise which would suggest the configure files are OK.

 

Thanks in advance.

Share this post


Link to post
Share on other sites
Has anyone got this to work?

I would live to see a copy of your admin/order.php file to see what i'm doing wrong.

Thanks in advance.

Raymond

 

Raymond,

 

Here is thee section from admin/orders.php I had to play around wit this, but mine works:

 

     // Customization #31101 for file_upload view begin
     $option = $order->products[$i]['attributes'][$j]['option'];
     ## Build a query to check if this option is of 'File' Type
     $file_check_sql = " select * from ".TABLE_PRODUCTS_OPTIONS ." o, ".TABLE_PRODUCTS_OPTIONS_TYPES." ot WHERE o.products_options_type = ot.products_options_types_id AND products_options_types_name='File' AND o.products_options_name='".$option."'";

     $file_check_sql_query = tep_db_query($file_check_sql);
     $isFile = tep_db_num_rows($file_check_sql_query);
     if($isFile == 1 && @file_exists(DIR_FS_CATALOG_IMAGES_UPLOADS.$order->products[$i]['attributes'][$j]['value'])){
      $file = "'" . DIR_WS_CATALOG_IMAGES_UPLOADS.$order->products[$i]['attributes'][$j]['value'] . "'";
       $link = "<a href=" . $file . "'target='_blank'><B><i>Click to View</i></B></a>";
     }else {
        $link = "";
     }

 

Hope this helps!

Travis

Share this post


Link to post
Share on other sites

Sorry, didn't give all the code there...

 

Insert code around line 240:

 

 if (isset($order->products[$i]['attributes']) && (sizeof($order->products[$i]['attributes']) > 0)) {
   for ($j = 0, $k = sizeof($order->products[$i]['attributes']); $j < $k; $j++) {

     // Customization #31101 for file_upload view begin
     $option = $order->products[$i]['attributes'][$j]['option'];
     ## Build a query to check if this option is of 'File' Type
     $file_check_sql = " select * from ".TABLE_PRODUCTS_OPTIONS ." o, ".TABLE_PRODUCTS_OPTIONS_TYPES." ot WHERE o.products_options_type = ot.products_options_types_id AND products_options_types_name='File' AND o.products_options_name='".$option."'";

     $file_check_sql_query = tep_db_query($file_check_sql);
     $isFile = tep_db_num_rows($file_check_sql_query);
     if($isFile == 1 && @file_exists(DIR_FS_CATALOG_IMAGES_UPLOADS.$order->products[$i]['attributes'][$j]['value'])){
      $file = "'" . DIR_WS_CATALOG_IMAGES_UPLOADS.$order->products[$i]['attributes'][$j]['value'] . "'";
       $link = "<a href=" . $file . "'target='_blank'><B><i>Click to View</i></B></a>";
     }else {
        $link = "";
     }

     echo '<br><nobr><small> <i> - ' . $order->products[$i]['attributes'][$j]['option'] . ': ' . $order->products[$i]['attributes'][$j]['value'];

     if ($order->products[$i]['attributes'][$j]['price'] != '0') echo ' (' . $order->products[$i]['attributes'][$j]['prefix'] . $currencies->format($order->products[$i]['attributes'][$j]['price'] * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']) . ')';
     echo ' ' . $link.' </i></small></nobr>';
      // Customization #31101 end
     }
}

 

You will also need to change a line in application_top.php:

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

to

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

 

Travis

Share this post


Link to post
Share on other sites

Hey Guys this is a great contribute, however i am using STS. Does anyone know how to get it to work with the product_info.php.html STS pages. I need to edit this code: in includes/sts_product_info.php

 

// Get the number of product attributes (the select list options)
$products_attributes_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "'");
$products_attributes = tep_db_fetch_array($products_attributes_query);
// If there are attributes (options), then...
if ($products_attributes['total'] > 0) {
 // Print the options header
 $template['optionheader'] = TEXT_PRODUCT_OPTIONS;

 // Select the list of attribute (option) names
 $products_options_name_query = tep_db_query("select distinct popt.products_options_id, popt.products_options_name from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "' order by popt.products_options_name");

 while ($products_options_name = tep_db_fetch_array($products_options_name_query)) {
   $products_options_array = array();
   $products_options_query = tep_db_query("select pov.products_options_values_id, pov.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov where pa.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pa.options_id = '" . (int)$products_options_name['products_options_id'] . "' and pa.options_values_id = pov.products_options_values_id and pov.language_id = '" . (int)$languages_id . "'");

   // For each option name, get the individual attribute (option) choices
   while ($products_options = tep_db_fetch_array($products_options_query)) {
     $products_options_array[] = array('id' => $products_options['products_options_values_id'], 'text' => $products_options['products_options_values_name']);

     // If the attribute (option) has a price modifier, include it
     if ($products_options['options_values_price'] != '0') {
       $products_options_array[sizeof($products_options_array)-1]['text'] .= ' (' . $products_options['price_prefix'] . $currencies->display_price($products_options['options_values_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) .') ';
     }

   }

   // If we should select a default attribute (option), do it here
   if (isset($cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name['products_options_id']])) {
     $selected_attribute = $cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name['products_options_id']];
   } else {
     $selected_attribute = false;
   }

   $template['optionnames'] .= $products_options_name['products_options_name'] . ':<br>'; 
   $template['optionchoices'] .=  tep_draw_pull_down_menu('id[' . $products_options_name['products_options_id'] . ']', $products_options_array, $selected_attribute) . "<br>"; 
 }
} else {
 // No options, blank out the template variables for them
 $template['optionheader'] = '';
 $template['optionnames'] = '';
 $template['optionchoices'] = '';

 

I've tried staring at the differents between the old product_info.php and new one but i just cant seem to get it :( Any help?

Share this post


Link to post
Share on other sites
Sorry, didn't give all the code there...

 

Insert code around line 240:

 

 if (isset($order->products[$i]['attributes']) && (sizeof($order->products[$i]['attributes']) > 0)) {
   for ($j = 0, $k = sizeof($order->products[$i]['attributes']); $j < $k; $j++) {

     // Customization #31101 for file_upload view begin
     $option = $order->products[$i]['attributes'][$j]['option'];
     ## Build a query to check if this option is of 'File' Type
     $file_check_sql = " select * from ".TABLE_PRODUCTS_OPTIONS ." o, ".TABLE_PRODUCTS_OPTIONS_TYPES." ot WHERE o.products_options_type = ot.products_options_types_id AND products_options_types_name='File' AND o.products_options_name='".$option."'";

     $file_check_sql_query = tep_db_query($file_check_sql);
     $isFile = tep_db_num_rows($file_check_sql_query);
     if($isFile == 1 && @file_exists(DIR_FS_CATALOG_IMAGES_UPLOADS.$order->products[$i]['attributes'][$j]['value'])){
      $file = "'" . DIR_WS_CATALOG_IMAGES_UPLOADS.$order->products[$i]['attributes'][$j]['value'] . "'";
       $link = "<a href=" . $file . "'target='_blank'><B><i>Click to View</i></B></a>";
     }else {
        $link = "";
     }

     echo '<br><nobr><small> <i> - ' . $order->products[$i]['attributes'][$j]['option'] . ': ' . $order->products[$i]['attributes'][$j]['value'];

     if ($order->products[$i]['attributes'][$j]['price'] != '0') echo ' (' . $order->products[$i]['attributes'][$j]['prefix'] . $currencies->format($order->products[$i]['attributes'][$j]['price'] * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']) . ')';
     echo ' ' . $link.' </i></small></nobr>';
      // Customization #31101 end
     }
}

 

You will also need to change a line in application_top.php:

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

to

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

 

Travis

 

Thanks for the code Travis. But for some reason it still does not work >_<

I will keep pluging away at it :thumbsup:

Share this post


Link to post
Share on other sites
Thanks for the code Travis. But for some reason it still does not work >_<

I will keep pluging away at it :thumbsup:

I think I found the problem. My order page shows this : Upload Picture: 49. Label1.jpg

But when I look in the upload file it shows this: Upload Picture: 49Label1.jpg

There seems to be a conflict in the file name.

I have no Ideal how to fix this, but I think this is the problem. I hope some expert can give me a hand :D

Thanks,

Raymond

Share this post


Link to post
Share on other sites
I think I found the problem. My order page shows this : Upload Picture: 49. Label1.jpg 

But when I look in the upload file it shows this: Upload Picture: 49Label1.jpg 

There seems to be a conflict in the file name.

I have no Ideal how to fix this, but I think this is the problem. I hope some expert can give me a hand :D

Thanks,

Raymond

 

I've exactly gthe same problem !

I can't see the "click to view" link on my admin/order page and the difference between names is exactly as described by giftmaster...

Share this post


Link to post
Share on other sites
I've exactly gthe same problem !

I can't see the "click to view" link on my admin/order page and the difference between names is exactly as described by giftmaster...

 

Ok I got this tip from reading this long post about 20 times :'(

In inclues/application_top.php. change:

 

  $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

CODE

  $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);

 

I now have the click to view, but...... I get this:

Forbidden

You don't have permission to access /shop/images/uploads/57.SnyderNewHome.jpg on this server.

 

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

 

Any Help?????????????

Raymond

Share this post


Link to post
Share on other sites

1146 - Table 'commerce.TABLE_PRODUCTS_OPTIONS_TYPES' doesn't exist

select products_options_types_id, products_options_types_name from TABLE_PRODUCTS_OPTIONS_TYPES where language_id='1' order by products_options_types_id

[TEP STOP]

This is the error I got when I try to add ?new prod attributes. What shall I do? The table does exist.

 

Thanks in advance

Ellinor

Share this post


Link to post
Share on other sites

I have this mod installed. It works fine except for one thing- when people upload file names with spaces in them it won't work. Say the filename is 23my picture.jpg. The link on the admin order page will be http://www.whateverdomainandfolders/23my

Like it's cutting it off at the space in the file name.

Is there a way to fix this? I've tried the fix at the top of the page here, but it doesn't make any difference.

Or is there a way to have the uploaded files renamed just to 23.jpg?

Share this post


Link to post
Share on other sites

Make sure that you have upgraded the database tables in admin/includes/database_tables.php you should have added this

 

define('TABLE_PRODUCTS_OPTIONS', 'products_options');

  define('TABLE_PRODUCTS_OPTIONS_TYPES', 'products_options_types');

  define('TABLE_PRODUCTS_OPTIONS_VALUES', 'products_options_values');

  define('TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS', 'products_options_values_to_products_options');

 

1146 - Table 'commerce.TABLE_PRODUCTS_OPTIONS_TYPES' doesn't exist

select products_options_types_id, products_options_types_name from TABLE_PRODUCTS_OPTIONS_TYPES where language_id='1' order by products_options_types_id

[TEP STOP]

This is the error I got when I try to add ?new prod attributes. What shall I do? The table does exist.

 

Thanks in advance

Ellinor

Share this post


Link to post
Share on other sites

Just make sure you explaign to everyone that they need to rename the files to not have spaces before they upload. You can make a short notice in the product description page.

 

You can still view the files by going into the image folder and by using the part 23my you can find it. If they upload a 2nd file named my whatever you will still know which is which by the # in front of it

 

This will work until someone comes up with a better solution

I have this mod installed.  It works fine except for one thing- when people upload file names with spaces in them it won't work.  Say the filename is 23my picture.jpg.  The link on the admin order page will be http://www.whateverdomainandfolders/23my

Like it's cutting it off at the space in the file name.

Is there a way to fix this?  I've tried the fix at the top of the page here, but it doesn't make any difference.

Or is there a way to have the uploaded files renamed just to 23.jpg?

Share this post


Link to post
Share on other sites

Just wondering if anyone got this to work or if they where able to atleast make a "Click to view" Link on the shopping cart page like they have on the admin/orders

The trouble is it not only inserts an image for the upload it makes all attributes into images.

 

I have managed to get an image of the upload in the shopping cart from the discussion on page 5 ish.

 

The trouble is it not only inserts an image for the upload it makes all attributes into images.

 

Here is the code from my shopping_cart.php, I just cant seem to alter it to only display uploads.

 

thanks guys,,

 

mes

 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>';
? ?$products_name .= '<br>' . tep_image(DIR_WS_UPLOADS . $products[$i][$option]['products_options_values_name'], $products[$i][$option]['products_options_values_name'], 250, 150) ?. '<br>';

 

Not to sure, but i'm assuming I need to insert a while clause infront of this bit of code?

 

CODE$products_name .= '<br>' . tep_image(DIR_WS_UPLOADS . $products[$i][$option]['products_options_values_name'], $products[$i][$option]['products_options_values_name'], 250, 150)  . '<br>';

 

somthing edited here?

 

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

Share this post


Link to post
Share on other sites
I have this mod installed.  It works fine except for one thing- when people upload file names with spaces in them it won't work.  Say the filename is 23my picture.jpg.  The link on the admin order page will be http://www.whateverdomainandfolders/23my

Like it's cutting it off at the space in the file name.

Is there a way to fix this?  I've tried the fix at the top of the page here, but it doesn't make any difference.

Or is there a way to have the uploaded files renamed just to 23.jpg?

 

Hi, I had the same problem and it looks as if I found a solution. However, I have pretty much zero knowledge about php and it would be good if somebody who knows what he/she is doing could verify this.

 

I added a function for replacing " " with "_" in the "set filename" functions of upload.php.

This is the replacement function that I added: $filename = str_replace(' ', '_', $filename);

 

I made the following changes in includes/classes/upload.php (I am not sure if it is needed in both functions or somewhere else too but it seems to work fine):

 

Replace this (around line 147):

 

function set_filename($filename) {

$this->filename = $filename;

}

 

function set_tmp_filename($filename) {

$this->tmp_filename = $filename;

}

 

With this:

function set_filename($filename) {

$filename = str_replace(' ', '_', $filename); //ut 0609 for removing possible spaces in the filename

$this->filename = $filename;

}

 

function set_tmp_filename($filename) {

$filename = str_replace(' ', '_', $filename); //ut 0609 for removing the spaces in the filename

$this->tmp_filename = $filename;

}

 

Let me know if it works.

 

Uli

Share this post


Link to post
Share on other sites

Hi,

 

I have installed this contrib and it appears perfect, but somehow I no longer have images on my product_info page. I have thumbs on the category pages. I have gone throught my code on that page and cannot find what the problems is. I ahve been searching in vain for a solution...any ideas?

 

Tim

Share this post


Link to post
Share on other sites

I encountered a strange problem in my newly installed file-upload contribution with the click-to-view modification of admin:

The uploaded files (in images/uploads directory) have permission 666 (rw-rw-rw-) so that it's not possible to view any of them.

 

The images and uploads directories had been chmod-ed to 777 before uploading.

 

The owner and group of the uploaded files are 99. (Sorry I'm a noob. What does 99 mean?) The situation is the same for uploaded category and sub-category images. But the latter don't have the same problem. (They can be viewed!)

 

In fact, I had modified the codes (in product_info.php, shopping_cart.php, checkout_confirmation.php & account_history_info.php) in order to enable customers to view the image files they upload. The problem prevents everybody including myself (the admin) to view the files from the web site.

 

Please help me. Thank you very much in advance.

Share this post


Link to post
Share on other sites

Sorry... I found that the problem has nothing to do with the file permission or owner. 666 is totally OK for accessing from website.

 

The problem was caused by .htaccess file.

Share this post


Link to post
Share on other sites

Wow! this seems to work awesome so far. Merging the files was PITA because I was afraid of overwritting contribs I've already installed. However I didn't have to do any fancy editing so it was worth the time to be sure.

 

It seems like it does not complete the upload until the order is completed. Is that correct? That is an awesome feature if so. Does it upload as soon as you say "add to cart" or does it wait until you get further down the process? I've only tested it with small files so I wasn't sure.

 

Also after I've used the customers files and want to delete them should I just get rid of them through FTP or do I need to remove them from a database anywhere as well?

 

Thanks for a great contrib that has saved me a ton of time.

Share this post


Link to post
Share on other sites

hey i downloaded and followed all steps to the best of my knowledge., and after all it gives me this error code :

this is when i click on "Product Attributes" in my admin section , i have added that line too that people were talkin about b4 , but still its still here.

do let me know how to fix this

 

If you want any additional file such as product attributes or configure.

please do ask if is needed .. i am new to oscommerce, i really need help.

 

Error Code:

 

1146 - Table 'primepr_jectoscommerce.products_options_types' doesn't exist

 

select products_options_types_id, products_options_types_name from products_options_types where language_id='1' order by products_options_types_id

 

[TEP STOP]

 

Thanks in advance,

 

Mark

Share this post


Link to post
Share on other sites
It seems like it does not complete the upload until the order is completed. Is that correct? That is an awesome feature if so. Does it upload as soon as you say "add to cart" or does it wait until you get further down the process? I've only tested it with small files so I wasn't sure.

 

Also after I've used the customers files and want to delete them should I just get rid of them through FTP or do I need to remove them from a database anywhere as well?

I installed mine over a year ago, so there may be changes since then. But on mine, it uploads the file when they click add to cart. If large files may be involved, you should add a text to the product page reminding them that large files may take a while. Also, if the files may ve very large, you may need to edit your php.ini file on the server to allow for large uploads and longer processing time.

 

I just delete mine through FTP (actually SFTP).


Rule #1: Without exception, backup your database and files before making any changes to your files or database.

Rule #2: Make sure there are no exceptions to Rule #1.

Share this post


Link to post
Share on other sites

hey,

I have tried all but still keep getting the same error

i really dont know why , im new to phpmyadmin.

 

1146 - Table 'primepr_jectoscommerce.products_options_types' doesn't exist

 

select products_options_types_id, products_options_types_name from products_options_types where language_id='1' order by products_options_types_id

 

[TEP STOP]

 

Heres a screenshot .. please let me know if there is somthing wrong with the page .. ..

product_optionsphp.jpg

 

thanks in advance,

 

mark

Share this post


Link to post
Share on other sites

Hi guys,

 

I experience a strange problem using this contribution. I installed everything as it is described in the manual but when I go to the attribute details page it shows me the following page:

 

os_com.jpg

 

Does anyone encountered this problem as well?

 

Thanks in advance,

 

Dominik

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  

×