| |
9 |
9 |
} |
| |
10 |
10 |
|
| |
11 |
11 |
# We check permissions on the object |
| |
12 |
12 |
permission::require_permission -object_id $object_id -privilege read |
| |
13 |
13 |
|
| |
14 |
14 |
# Get information about attachment |
| |
15 |
15 |
set content_type [item::get_type $attachment_id] |
| |
16 |
16 |
if { [string length $content_type] == 0 } { |
| |
17 |
17 |
ad_return_complaint 1 [_ attachments.lt_No_such_attachment_fo] |
| |
18 |
18 |
return |
| |
19 |
19 |
} |
| |
20 |
20 |
|
| |
21 |
21 |
switch $content_type { |
| |
22 |
22 |
content_extlink { |
| |
23 |
23 |
ad_returnredirect [db_string select_url {}] |
| |
24 |
24 |
ad_script_abort |
| |
25 |
25 |
return |
| |
26 |
26 |
} |
| |
27 |
27 |
|
| |
28 |
28 |
file_storage_object { |
| |
29 |
|
set title [db_string select_attachment_title {}] |
| |
|
29 |
db_1row select_attachment {} |
| |
|
30 |
|
| |
|
31 |
# Test if the filename contains the extension, otherwise append it |
| |
|
32 |
# This usually happens if you just rename the title (displayed filename) but forget |
| |
|
33 |
# to append the extension to it. |
| |
|
34 |
set extension [file extension $title] |
| |
|
35 |
if {$extension ne $file_extension} { |
| |
|
36 |
append title ".${file_extension}" |
| |
|
37 |
} |
| |
30 |
38 |
ad_returnredirect "download/[ad_urlencode $title]?object_id=$object_id&attachment_id=$attachment_id" |
| |
31 |
39 |
ad_script_abort |
| |
32 |
40 |
return |
| |
33 |
41 |
} |
| |
34 |
42 |
|
| |
35 |
43 |
default { |
| |
36 |
44 |
ad_return_complaint 1 [_ attachments.lt_dont_know_how_to_deal [list content_type $content_type]] |
| |
37 |
45 |
return |
| |
38 |
46 |
} |
| |
39 |
47 |
} |