1 | <?php
|
---|
2 | if (INCLUDED!==true) exit('Dieee !!!');
|
---|
3 | ?>
|
---|
4 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
---|
5 | <head>
|
---|
6 | <title>upload</title>
|
---|
7 | <meta http-equiv="Content-Type" content="text/html; charset=windows-1251"/>
|
---|
8 | </head>
|
---|
9 | <body leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0">
|
---|
10 | <?php
|
---|
11 | global $valid_dirs;
|
---|
12 | $_GET[def_dir] ? $def_dir = $_GET[def_dir] : $def_dir = 0 ;
|
---|
13 | $_POST[lib] ? $cur_dir = $_POST[lib] : $cur_dir = $valid_dirs[$def_dir];
|
---|
14 | if($_FILES['attach']['name']){
|
---|
15 | $cur_file = my_uploadfile('attach', $cur_dir);$selfile = $cur_file;
|
---|
16 | $cur_file = $cur_dir.$cur_file;
|
---|
17 | }else{$cur_file = "";$selfile="";}
|
---|
18 |
|
---|
19 | $dir_list = viewdir_list($valid_dirs, $cur_dir);
|
---|
20 | $file_list = viewdir($cur_dir,$selfile);
|
---|
21 | ?>
|
---|
22 | <script language="javascript">
|
---|
23 | <!--
|
---|
24 | function selectClick()
|
---|
25 | {
|
---|
26 | if (document.getElementById('lib').selectedIndex>=0 && document.getElementById('imglist').selectedIndex>=0)
|
---|
27 | {
|
---|
28 | inc = document.getElementById('lib').options[document.getElementById('lib').selectedIndex].value + document.getElementById('imglist').options[document.getElementById('imglist').selectedIndex].value;
|
---|
29 | //opener.wrap_tags(inc,'textarea');
|
---|
30 | <?php if($_GET[mode2]=='av'){ ?>
|
---|
31 | opener.document.getElementById('r_avatar').value = inc;
|
---|
32 | <?php }else{ ?>
|
---|
33 | opener.document.getElementById('textarea').value += '[img]'+inc+'[/img]';
|
---|
34 | <?php } ?>
|
---|
35 | window.close();
|
---|
36 | }
|
---|
37 | else
|
---|
38 | {
|
---|
39 | alert('<?php echo 'error_no_image';?>');
|
---|
40 | }
|
---|
41 | }
|
---|
42 | //-->
|
---|
43 | </script>
|
---|
44 | <div class="error_box" style="float:left; width:180px; height:440px;">
|
---|
45 | <form name="libbrowser" id="libbrowser" method="post" action="<?php echo$_SERVER['PHP_SELF']."?n=upload";?>" enctype="multipart/form-data">
|
---|
46 | <select name="lib" id="lib" size="1" class="input" style="width: 180px;" onChange="document.getElementById('libbrowser').submit();">
|
---|
47 | <?php echo $dir_list?>
|
---|
48 | </select>
|
---|
49 | <br><br>
|
---|
50 | <select name="imglist" id="imglist" size="22" class="input" style="width: 180px;"
|
---|
51 | onchange="if (this.selectedIndex >=0) document.getElementById('imgpreview').src = document.getElementById('lib').options[document.getElementById('lib').selectedIndex].value + this.options[this.selectedIndex].value;" ondblclick="selectClick();">
|
---|
52 | <?php echo $file_list?>
|
---|
53 | </select>
|
---|
54 | ^ <?php echo$lang[uploaddblclk];?> ^
|
---|
55 | </form>
|
---|
56 | </div>
|
---|
57 | <div class="error_box" style="float:right; width:365px; height:440px;">
|
---|
58 | <iframe name="imgpreview" id="imgpreview" src="<?php echo $cur_file;?>" style="width: 340px; height: 100%;" scrolling="Auto" marginheight="0" marginwidth="0" frameborder="0"></iframe>
|
---|
59 | </div>
|
---|
60 | <div class="error_box" style="clear:both; width:95%;">
|
---|
61 | <form action="<?php echo$_SERVER['PHP_SELF']."?n=upload";?>" method="post" name="upl_attach" enctype="multipart/form-data">
|
---|
62 | <input type="hidden" name="lib" value="<?php echo$cur_dir;?>">
|
---|
63 | <div class="form-item" id="upl">
|
---|
64 | <label><?php echo$lang[file];?></label><br>
|
---|
65 | <input class="form-text" name="attach" size="28" value="" type="file">
|
---|
66 | <input class="form-submit" name="do" value="<?php echo$lang[upload];?>" type="submit">
|
---|
67 |
|
---|
68 | <input class="form-submit" value="<?php echo$lang[close];?>" type="button" onClick="javascript:window.close();">
|
---|
69 | </div>
|
---|
70 | </form>
|
---|
71 | </div>
|
---|
72 | <?php
|
---|
73 | function my_uploadfile($name, $dir) {
|
---|
74 |
|
---|
75 | global $valid_files;
|
---|
76 |
|
---|
77 | if($dir{0}=='/'){
|
---|
78 | $d_root = str_replace('\\','/',$_SERVER['DOCUMENT_ROOT']);
|
---|
79 | $d_root = $d_root.$dir;
|
---|
80 | $d_root = str_replace('//','/',$d_root);
|
---|
81 | }else{
|
---|
82 | $d_root = $dir;
|
---|
83 | }
|
---|
84 |
|
---|
85 | $img_file_var = $_FILES[$name];
|
---|
86 | if ($img_file_var['size']>0) {
|
---|
87 | $data['type'] = $img_file_var['type'];
|
---|
88 | $data['name'] = $img_file_var['name'];
|
---|
89 | $data['size'] = $img_file_var['size'];
|
---|
90 | $data['tmp_name'] = $img_file_var['tmp_name'];
|
---|
91 | // get file extension
|
---|
92 | $ext = strtolower(substr(strrchr($data['name'],'.'), 1));
|
---|
93 | if (in_array($ext,$valid_files)) {
|
---|
94 | $dir_name = $d_root;
|
---|
95 | $img_name = $data['name'];
|
---|
96 | $i = 1;
|
---|
97 | while (file_exists($dir_name.$img_name)) {
|
---|
98 | $img_name = ereg_replace('(.*)(\.[a-zA-Z]+)$', '\1_'.$i.'\2', $data['name']);
|
---|
99 | $i++;
|
---|
100 | }
|
---|
101 | if (!move_uploaded_file($data['tmp_name'], $dir_name.$img_name)) {
|
---|
102 | return false;
|
---|
103 | }
|
---|
104 | return $img_name;
|
---|
105 | }
|
---|
106 | else
|
---|
107 | {
|
---|
108 | }
|
---|
109 | }
|
---|
110 | return false;
|
---|
111 | }
|
---|
112 |
|
---|
113 | function viewdir($dir, $sel = '')
|
---|
114 | {
|
---|
115 | global $valid_files;
|
---|
116 | $buf = '';
|
---|
117 | if($dir{0}=='/'){
|
---|
118 | $d_root = str_replace('\\','/',$_SERVER['DOCUMENT_ROOT']);
|
---|
119 | $d_root = $d_root.$dir;
|
---|
120 | $d_root = str_replace('//','/',$d_root);
|
---|
121 | }else{
|
---|
122 | $d_root = $dir;
|
---|
123 | }
|
---|
124 | $handle = opendir($d_root);
|
---|
125 | while (false !== ($file = readdir($handle)))
|
---|
126 | {
|
---|
127 | $path_parts = pathinfo($d_root.$file);
|
---|
128 | //echo $path_parts[extension].'<br>';
|
---|
129 | if (in_array($path_parts[extension],$valid_files)) {
|
---|
130 | //echo "$file <br>\n";
|
---|
131 | $buf .= '<option value="'.$file.'"'.(($file == $sel)?' selected':'').'>'.$file.'</option>'."\n";
|
---|
132 | }
|
---|
133 | }
|
---|
134 | closedir($handle);
|
---|
135 | return $buf;
|
---|
136 | }
|
---|
137 |
|
---|
138 | function get_droot($dir)
|
---|
139 | {
|
---|
140 | if($dir{0}=='/'){
|
---|
141 | $d_root = str_replace('\\','/',$_SERVER['DOCUMENT_ROOT']);
|
---|
142 | $d_root = $d_root.$dir;
|
---|
143 | $d_root = str_replace('//','/',$d_root);
|
---|
144 | }else{
|
---|
145 | $d_root = $dir;
|
---|
146 | }
|
---|
147 | return $d_root;
|
---|
148 | }
|
---|
149 |
|
---|
150 | function viewdir_list($arr, $sel = '')
|
---|
151 | {
|
---|
152 | $buf = '';
|
---|
153 | foreach($arr as $val) {
|
---|
154 | $buf .= '<option value="'.$val.'"'.(($val == $sel)?' selected':'').'>'.$val.'</option>'."\n";
|
---|
155 | }
|
---|
156 | return $buf;
|
---|
157 | }
|
---|
158 |
|
---|
159 | ?>
|
---|