68 replies [Last post]
csdesignco's picture
Offline
Joined: 02/10/2010
Juice: 230
Re: Re: subscribing. Very interested

Just ran into a huge problem with this module. Around line 510 is function "_uc_attribute_files_rrmdir($dir)" which just wiped out most of my drupal installation when Cron ran. I'm not yet certain why it was affecting anything outside the scope of the files directory, except to say that if the $dir variable is not set it will definitely attempt to unlink everything from the root path on. This just set me back in a huge way.

csdesignco's picture
Offline
Joined: 02/10/2010
Juice: 230
Re: Re: Re: subscribing. Very interested

Just adding more thoughts as I find them.

The unlink issue above was a result of cron running before I had set the default upload directory for this module. Since one did not exist, it attempted (and succeeded in many cases!) to delete everything from the base_path on. Ouch. I have since commented out the function _uc_attribute_files_rrmdir as I don't see it as necessary to my needs.

Another issue that I've discovered that is worth sharing is that there is a disconnect between where files are uploaded (they are properly uploaded to the directory specified at admin/store/settings/attributes) but the link that is sent out specifies some kind of default directory, /uploads/orders/1/[order-id]/[filename].

csdesignco's picture
Offline
Joined: 02/10/2010
Juice: 230
Re: Re: Re: Re: subscribing. Very interested

The function uc_attribute_files_cart_validate() is running regardless of whether the file attachment is required attribute; this results in users receiving an error for "incorrect file type" if they choose to not upload a file. I am not sure of the proper way to only have the function run if the attribute is not required and a file was updated. In my case, I never require file uploads (they are optional) so I have included this IF function just inside uc_attribute_files_cart_validate():

<?php
if (strlen($_FILES['files']['name']['Artwork file'] > 0)) {
 
// perform uc_attribute_files_cart_validate function as normal
}
return
true;
?>

I also had to modify uc_attribute_files_value_callback() with the same IF function, as the Drupal function file_munge_filename() runs on every "add to cart", again regardless of the file's existence or not, and gives users a message "For security reasons, your file was renamed to ..".

garydev's picture
Offline
Joined: 03/02/2011
Juice: 24
Can I get a clarificatin of this Module's functionality

Thanks for the tip csdesignco -

I have a need to pass an image from a Druplash (Drupal + Flash) front end to Ubercart (user's cart).

I am using Cart Links formatting to pass a variety of variables to text field attributes. These variables are being passed and working properly.

This is the result being passed to the cart:
http://mysite.com/cart/add/p1070_q1_a34ohttp%3A//www.mysite.com/dev/temp...

So I am trying to pass this url:http//www.mysite.com/dev/temp/image41378438.jpg as the attribute id a34o - (this is a snapshot of a custom design created by the user)

Something is stripping the "//" from the url. So I have tried a variety of methods to escape those characters ie. http%3A//www.mysite.com/dev/temp/image41378438.jpg

But it always loads only http: into the text field attribute and then the return breaks (because the URL is the first attribute). When URL is excluded the other attributes update perfectly.

So does this module allow for the image that is created in my Flash front-end to be loaded into the user's shopping cart as a demonstration of the user's design? Remember that the user's "upload" will be done dynamically.

Also - I read in this thread about developers losing all their data. If there is a remote possibility for this I need to know it.

Otherwise, I'm happy to present a link. Anyone know how to accomplish the passing of a URL through Cart Links format?

Thanks -

Using Drupal 6.x

garydev's picture
Offline
Joined: 03/02/2011
Juice: 24
Bump

Anyone with any guidance? I would be just as happy to pass the actual image back into the cart as an attribute -

I could also pass the image into a swf, but I can't figure out how to get the swf into the product description.

In another thread I received some advice to use base64 encoding - so I encoded the file in and now I'm trying to decode it. Any advice on where to place the decode php would be most helpfule.

Thanks!

pablov2's picture
Offline
Joined: 04/08/2011
Juice: 8
check if there are not any files uploading

Hi all,

I have added this code to check if there are not files uploading:

<?php  
//line 442 in uc_attribute_files.module

if (empty($_FILES['files']['name']))    {

      

// here  -> Validate file type & file was uploaded properly

}else {   drupal_set_message('No ha subido ningún fichero.');  return true;  }

?>
Lex van Sonderen's picture
Offline
Joined: 05/14/2011
Juice: 3
move to github?

I did some tracing of the code and the wiping of all the files may happen sooner than at cron.

function uc_attribute_files_user($op, &$edit, &$user, $category = NULL)

calls:

uc_attribute_files_move_files($dir . "/" . $edit['uc_attribute_files_cartid'], $dir . '/' . uc_cart_get_id());

which may delete all your files or move your complete drupal installation to /1/ if you happen to have an uploaded file in your cart (and a server that allows deletion of source files by PHP).

as resolution I added sensible defaults for the cart and order upload directory paths to uc_attribute_files.install

function uc_attribute_files_install() {
variable_set('uc_attribute_files_cart_filepath', file_directory_path() . '/cart');
variable_set('uc_attribute_files_order_filepath', file_directory_path() . '/orders');
}

I also uploaded this module to github, so we can collect all fixes in one place.
see:
https://github.com/Drupalfarms/uc_attribute_files

csdesignco's picture
Offline
Joined: 02/10/2010
Juice: 230
Re: move to github?

Thanks for setting up a github page. Good job setting up the sensible defaults. This post and my experience above just show us in-the-wild examples of 2 important practices:

1) The only folder that should be writable by the web server is your Drupal files directory.
2) Modules should always write to folders within the files directory via file_directory_path() and never to a folder in Drupal root / in a module sub folder / etc.

pablov2's picture
Offline
Joined: 04/08/2011
Juice: 8
Re: [Almost Complete] - Handling upload of file as an attribute

I will try it now, but I am not sure, is this the last version http://www.dlogan.net/drupal/uc_attribute_files_Beta_0.65.tar.gz ??

Thxxx

csdesignco's picture
Offline
Joined: 02/10/2010
Juice: 230
Re: Re: [Almost Complete] - Handling upload of file as an attrib

garydev -- look at the source code for this module and you'll see similar code... look for the string "[UBERCART" (without quotes) and I believe you should find hooks where you can do this.

pablov2 -- I believe that's the latest version to use -- just make sure you go to the attributes page immediately after enabling the module and set your directories, otherwise when cron runs this module will attempt to unlink (delete) your entire Drupal folder.

pablov2's picture
Offline
Joined: 04/08/2011
Juice: 8
Hide empty attribute

If I dont upload any file, I can continue with the checkout but in the cart it still appears.

I`ve tried to hide it but I can`t found where is the code to check it. Any idea?

AttachmentSize
uc_attributes_file.png 32.92 KB
karc's picture
Offline
Joined: 05/28/2008
Juice: 72
Same issue here

Same issue here,

regardless a file was uploaded or not, the option appears in cart. with a link to /uploads/cart on a "." Like This: Upload: .

I also would be happy, if someone could make this 100% work. (also because of the message:" for security reasons..."). I also would pay someone for it, as long as it is affordable.

This code:

<?php
if (strlen($_FILES['files']['name']['Artwork file'] > 0)) {
 
// perform uc_attribute_files_cart_validate function as normal
}
return
true;
?>

helped to get rid of it, but when i´m putting this code in the function: uc_attribute_files_value_callback(), then the correct path to the uploaded file is gone in the cart. instead of that I just got that empty link, mentioned above.

is someone still working on this module or is ist doomed? Is there a new version available?

Thanks for any help,
Marc

luk82's picture
Offline
Joined: 11/25/2011
Juice: 3
Re: Same issue here

This worked for me "for security reasons" prompt will go away after adding IF to form validation function and uc_attribute_files_value_callback(). This module works pretty well Smiling

johngflower's picture
Offline
Joined: 01/04/2009
Juice: 88
Re: [Almost Complete] - Handling upload of file as an attribute

There appears to be a spelling mistake at Ln 469. %lable ought to be %label in uc_attribute_files.module
Ln 469 form_set_error($id, t('!filename: File upload failed for %label.', array('!filename' => $filename, '%lable' => $attribute->label)));

Can I propose a relabelling of the package category in uc_attribute_files to:-
package = "Ubercart - extra"
This way it'd show up with the other Ubercart addons, instead of in it's own, separate, category.

Marameo Design's picture
Offline
Joined: 03/14/2011
Juice: 26
Not really working

Hi Guys,

I have tried to install this and seems to be working just fine. When I create the order i can click on my image and it will appear a download window. Great.
Problem is once the order is placed, and as store admin I review the order, if I click on the file name I get a file not found!

I would be happy to sponsor this in order to have it in good working order.

If you can help anyway please let me know, as I don't have much time to finish this project and I need this functionality.

Thank you.

hillsdave's picture
Offline
Joined: 10/19/2011
Juice: 4
Drupal 7?

Anyone know how to get this to work in Drupal 7.8?

larowlan's picture
Offline
Joined: 08/10/2008
Juice: 83
Re: [Almost Complete] - Handling upload of file as an attribute

Have a look at my fork on the github site (larowlan on github too).
It's working fairly well and I'd welcome comments.
It's a major rewrite to use the drupal file api and user_files module to handle permissions etc.

showitoff's picture
Offline
Joined: 02/09/2012
Juice: 6
Re: [Almost Complete] - Handling upload of file as an attribute

Just curious...I didn't see it clearly outlined anywhere, so if anyone asked already, I'm sorry!

Is this at all compatible with drupal 7, and ubercart 3?