| |
1 |
1 |
# /www/admin/file-manager/file-upload-2.tcl |
| |
2 |
2 |
|
| |
3 |
3 |
ad_page_contract { |
| |
4 |
4 |
|
| |
5 |
5 |
Process a file upload |
| |
6 |
6 |
|
| |
7 |
7 |
@author ron@arsdigita.com |
| |
8 |
8 |
@creation-date Fri May 26 06:39:29 2000 |
| |
9 |
9 |
@cvs-id $Id$ |
| |
10 |
10 |
} { |
| |
11 |
11 |
{path:trim,notnull} |
| |
12 |
12 |
{message:trim,notnull} |
| |
13 |
13 |
{title:trim,notnull} |
| |
14 |
14 |
} |
| |
15 |
15 |
|
| |
16 |
16 |
set the_file [ns_queryget the_file.tmpfile] |
| |
17 |
17 |
|
| |
18 |
18 |
# Make sure the incoming filename is valid |
| |
19 |
19 |
|
| |
20 |
20 |
if ![fm_valid_filename_p $title] { |
| |
21 |
|
ad_return_complaint "<li>Invalid file name (no spaces, & or /'s)" |
| |
|
21 |
ad_return_complaint "Error" "<li>Invalid file name (no spaces, & or /'s)" |
| |
22 |
22 |
ad_script_abort |
| |
23 |
23 |
} |
| |
24 |
24 |
|
| |
25 |
25 |
if {![empty_string_p $title] && [empty_string_p [file ext $title]]} { |
| |
26 |
|
ad_return_complaint " |
| |
|
26 |
ad_return_complaint "Error" " |
| |
27 |
27 |
<li>The title you supply must have one of the following extensions:<br> |
| |
28 |
28 |
[ad_parameter Extensions file-manager]" |
| |
29 |
29 |
ad_script_abort |
| |
30 |
30 |
} |
| |
31 |
31 |
|
| |
32 |
32 |
# Done with error checking |
| |
33 |
33 |
|
| |
34 |
34 |
set path [file join $path $title] |
| |
35 |
35 |
|
| |
36 |
36 |
# Check the file type |
| |
37 |
37 |
|
| |
38 |
38 |
set file_type [exec file $the_file] |
| |
39 |
39 |
|
| |
40 |
40 |
# If the file is text then read it, strip carriage returns, |
| |
41 |
41 |
# and write to the destination path |
| |
42 |
42 |
|
| |
43 |
43 |
if {[regexp -nocase -- {\.adp} $path]} { |
| |
44 |
44 |
if [catch { |
| |
45 |
45 |
|
| |
46 |
46 |
set fd [open $the_file r] |
|
| |
90 |
90 |
# for Mac |
| |
91 |
91 |
regsub -all "\r" $text "\n" text |
| |
92 |
92 |
|
| |
93 |
93 |
set fd [open $path w] |
| |
94 |
94 |
puts $fd $text |
| |
95 |
95 |
close $fd |
| |
96 |
96 |
|
| |
97 |
97 |
} else { |
| |
98 |
98 |
# if the file is binary just copy it |
| |
99 |
99 |
ns_cp $the_file $path |
| |
100 |
100 |
} |
| |
101 |
101 |
|
| |
102 |
102 |
# Register what we did with the version control system if necessary |
| |
103 |
103 |
|
| |
104 |
104 |
if [ad_parameter VersionControlP file-manager 0] { |
| |
105 |
105 |
|
| |
106 |
106 |
# get the editor's name and email address for the log |
| |
107 |
107 |
set user_id [ad_verify_and_get_user_id] |
| |
108 |
108 |
|
| |
109 |
109 |
db_1row user_info { |
| |
110 |
|
select first_names || ' ' || last_name as name, |
| |
111 |
|
email |
| |
112 |
|
from users |
| |
113 |
|
where user_id = :user_id |
| |
|
110 |
select pe.first_names || ' ' || pe.last_name as name, |
| |
|
111 |
pa.email |
| |
|
112 |
from persons pe, parties pa |
| |
|
113 |
where pe.person_id=pa.party_id and pa.party_id = :user_id |
| |
114 |
114 |
} |
| |
115 |
115 |
|
| |
116 |
116 |
# add the file (just in case) and commit the change |
| |
117 |
117 |
vc_add $path |
| |
118 |
118 |
vc_commit $path "$name ($email) - $message" |
| |
119 |
|
|
| |
120 |
|
db_release_unused_handles |
| |
121 |
119 |
} |
| |
122 |
120 |
|
| |
123 |
121 |
ad_returnredirect "file-list?path=[file dirname $path]" |
| |
124 |
122 |
|