Downloads

Locked

Started by makc on 11 Aug 2006, 7:35 AM · Views: 3,784

Results 1 to 15 of 15
This thread is locked. New replies are disabled.
11 Aug 2006, 7:35 AM
#1
makc avatar

makc

New Zenner

Join Date:
Aug 2006
Posts:
56
Plugin Contributions:
0

Downloads

There seem to be few problems with downloads. Perhaps this is my misconception, let me know if this is so.

  • headers are always sent, but have no effect unless DOWNLOAD_BY_REDIRECT is false.
  • when DOWNLOAD_BY_REDIRECT is false, data is always sent with Application/octet-stream. in my case, files are images and I am required to display them in the browser; with that said, there could be other media types in near future. meaning: headers must be configureable via attributes controller in one way or another, like file name is.
  • speaking of file names, Content-disposition doesn't seem to do the trick, IE keeps suggesting "index.jpg" (I'm looking into this issue right now).
  • when DOWNLOAD_BY_REDIRECT is true, I can't find any code that removes symlinks. where is it?
  • also, I keep thinking what can be done with "no-cache" headers in case of multiple/unlimited downloads.

The reason why I am posting this thread here, is because I am going to have to change this code any way, so I thought that perhaps team/community might be interested in these changes, and coordinate my changes before I made them.

Thanks for consideration.

11 Aug 2006, 7:58 AM
#2
makc avatar

makc

New Zenner

Join Date:
Aug 2006
Posts:
56
Plugin Contributions:
0

Re: Downloads

it appears that current code does not add semicolon after file name. is semicolon essential? also, here it is suggested to use application/download content type. I'm puzzled...

11 Aug 2006, 9:24 AM
#3
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,511
Plugin Contributions:
176

Re: Downloads

makc:

when DOWNLOAD_BY_REDIRECT is true, I can't find any code that removes symlinks. where is it?
The unlink happens the next time someone downloads a file via zen_unlink_temp_dir()

it appears that current code does not add semicolon after file name. is semicolon essential?according to pattern, the other headers don't supply a semicolon unless an additional parameter is supplied. I suppose either way may be suitable.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

11 Aug 2006, 9:50 AM
#4
makc avatar

makc

New Zenner

Join Date:
Aug 2006
Posts:
56
Plugin Contributions:
0

Re: Downloads

yes zen_unlink_temp_dir(DIR_FS_DOWNLOAD_PUBLIC) is right there, I must have been temporary blind when skimming through the code :blush: so I suppose @unlink($dir . $subdir . '/' . $file) just fails silently if file is still in use?

11 Aug 2006, 10:10 AM
#5
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,511
Plugin Contributions:
176

Re: Downloads

the @ supresses failure conditions

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

12 Aug 2006, 1:18 PM
#6
makc avatar

makc

New Zenner

Join Date:
Aug 2006
Posts:
56
Plugin Contributions:
0

Re: Downloads

now that's not what I was asking for, is it :wink2: any way, original code has big bug - it does not terminate its output after reading a file, and some browsers (IE6) react in a strange manner. this can be easily fixed with one die() call, and will be included in my code - so stay tuned :cool:

12 Aug 2006, 9:49 PM
#7
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,511
Plugin Contributions:
176

Re: Downloads

Big Bug?

I've never seen that happen when testing downloads, whether in IE or FF or Opera.

What exact settings do you have active in order to trigger this?

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

13 Aug 2006, 4:10 AM
#8
makc avatar

makc

New Zenner

Join Date:
Aug 2006
Posts:
56
Plugin Contributions:
0

Re: Downloads

I have no idea what causes that. I have IE6.0, Apache1.3, PHP5 on win32. Something out of this causes php output more than it should. Any way, zen_exit() fixes that, as I said.

I also found my filename problem source, someone was lazy and did not use basename() in Content-disposition :wink2:

There's peculiar situation with unlimited downloads. In header_php.php, 1.3.0.2 ignores download_count when maxdays = 0. In tpl_modules_downloads.php, there's a comment saying download link should only appear if remaining count is > 0, but code itself is modified to match header_php.php logic. So when maxdays = 0, download_count is decremented, but ignored. What's the point? Any way, it is good that unlimited downloads are already in code. Whoever wants counter to work can simply set download to expire in 10000 days, right?

Another q-n is why the link on download button is always displayed. Since that seem to be the only way the customer can get to download expiration page, I have left it in place, but made the button to read "expired" when it is.

One have sh*tload of files to change just to get one feature right, that sucks guys. I wonder if anything will be done about it in 2.x? Does someone in team work on 2.x, btw? Any way, I added basic control over headers both to attribute and download managers, fixed minor bugs and improved few other things along the way. Here are my code changes, feel free to windiff it to death. I hope it will find its way into 1.3.0.3 (or else it will be a pain for me to upgrade).

Fheew, what a night it was :wacko: Gotta go take a shower.

13 Aug 2006, 9:26 AM
#9
makc avatar

makc

New Zenner

Join Date:
Aug 2006
Posts:
56
Plugin Contributions:
0

Re: Downloads

^^^ just a quick update, sort of "did you know" sh*t. did you know? zen_copy_products_attributes does not copy downloads! :censored: :bangin: :blink:

13 Aug 2006, 9:29 AM
#10
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,511
Plugin Contributions:
176

Re: Downloads

makc:

did you know? zen_copy_products_attributes does not copy downloads!
Yes - that's by design.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

13 Aug 2006, 2:07 PM
#11
makc avatar

makc

New Zenner

Join Date:
Aug 2006
Posts:
56
Plugin Contributions:
0

Re: Downloads

DrByte:

Yes - that's by design.

Hmm. I noticed that when I tried to copy download product. New product had no files. Is there another button I am supposed to click to complete the process?

A word about header_php. In download by redirect case, I have left code unchanged, because there's little to nothing that can be done about this code; it has no control over headers server sends after client is redirected. I keep looking at this part, though```
$download_link = str_replace(array('/','\'),'_',$downloads->fields['orders_products_filename']);
$link_create_status = symlink(..., DIR_FS_DOWNLOAD_PUBLIC . $tempdir . '/' . $download_link);


Also, I think it would be good idea to send 303 status for redirects rather than Location only with zen_redirect().> **RFC 2616, 10.3.4:**
>
> The response to the request can be found under a different URI and
>    SHOULD be retrieved using a GET method on that resource. This method
>    exists primarily to allow the output of a POST-activated script to
>    redirect the user agent to a selected resource... The 303
>    response MUST NOT be cached, but the response to the second
>    (redirected) request might be cacheable.This could allow files to be cached AND download counters to be still decremented.
13 Aug 2006, 6:42 PM
#12
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,511
Plugin Contributions:
176

Re: Downloads

makc:

Hmm. I noticed that when I tried to copy download product. New product had no files. Is there another button I am supposed to click to complete the process?No other buttons to click. You need to set up the file attributes separately.

Your other points are interesting and would require thorough testing. As to the '.', perhaps using ./ instead might be enough. Or maybe check whether the . is the first character or not before acting on it.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

14 Aug 2006, 9:31 AM
#13
makc avatar

makc

New Zenner

Join Date:
Aug 2006
Posts:
56
Plugin Contributions:
0

Re: Downloads

no, I was thinking about replacing extension dot specifically, so that server wouldn't do us a favour and send Content-Type when we don't want that.

30 Aug 2006, 12:32 AM
#14
true_smilez avatar

true_smilez

New Zenner

Join Date:
Apr 2006
Posts:
14
Plugin Contributions:
0

Re: Downloads

makc:

I have no idea what causes that. I have IE6.0, Apache1.3, PHP5 on win32. Something out of this causes php output more than it should. Any way, zen_exit() fixes that, as I said.

I also found my filename problem source, someone was lazy and did not use basename() in Content-disposition :wink2:

There's peculiar situation with unlimited downloads. In header_php.php, 1.3.0.2 ignores download_count when maxdays = 0. In tpl_modules_downloads.php, there's a comment saying download link should only appear if remaining count is > 0, but code itself is modified to match header_php.php logic. So when maxdays = 0, download_count is decremented, but ignored. What's the point? Any way, it is good that unlimited downloads are already in code. Whoever wants counter to work can simply set download to expire in 10000 days, right?

Another q-n is why the link on download button is always displayed. Since that seem to be the only way the customer can get to download expiration page, I have left it in place, but made the button to read "expired" when it is.

One have sh*tload of files to change just to get one feature right, that sucks guys. I wonder if anything will be done about it in 2.x? Does someone in team work on 2.x, btw? Any way, I added basic control over headers both to attribute and download managers, fixed minor bugs and improved few other things along the way. Here are my code changes, feel free to windiff it to death. I hope it will find its way into 1.3.0.3 (or else it will be a pain for me to upgrade).

Fheew, what a night it was :wacko: Gotta go take a shower.
HI makc, Thanks for your brilliant efforts.
I am having exactly same problem, I've tried all possible things, I applied your solution as well, but somehow I can't figure it out.
I am running

  • Zen Cart 1.3.0.2
  • Database Patch Level: 1.3.0.2
  • Windows 2000 Server
  • IIS 6.0/
  • PHP Version 4.4.2
  • Type Application/octet-stream
  • Download by redirect = False
  • Pub is correct directory permissions
  • All files are under 1 MB and in ZIP format without any special char or space (available in download directory)
  • sessions are configured correctly in php.ini and includes/configure.php
    test url: http://shop.imranseries.com
    Can you please take me out from it without asking me how I came in ;) I am totally stuck mate for last 2 month, been advised to upgrade from 1.2x to 1.3.x and that was a big pain... and also to apply your patch in 1.3x.plz help me....
    Cheers
30 Aug 2006, 7:37 AM
#15
makc avatar

makc

New Zenner

Join Date:
Aug 2006
Posts:
56
Plugin Contributions:
0

Re: Downloads

I 'm not sure what your problem is, I have just downloaded some zip file from your site without problems. Any way, you seem to be using standard settings, so there is no need to port my whole patch, you might only need to add exit call in downloads header php.