source: sandbox/filemanager/inc/upload.php @ 1924

Revision 1924, 5.5 KB checked in by amuller, 14 years ago (diff)

Ticket #597 - Implementação de Drag and Drop

  • Property svn:executable set to *
Line 
1<?php
2require_once '../../header.session.inc.php';
3
4/* This single file is used to increase upload_max_filesize and post_max_size using .htaccess*/
5if(!isset($GLOBALS['phpgw_info'])){
6        $GLOBALS['phpgw_info']['flags'] = array(
7                'currentapp' => 'filemanager',
8                'nonavbar'   => true,
9                'noheader'   => true
10        );
11}
12require_once '../../header.inc.php';
13
14$bo = CreateObject('filemanager.bofilemanager');
15
16$c = CreateObject('phpgwapi.config','filemanager');
17$c->read_repository();
18$current_config = $c->config_data;
19$upload_max_size = $current_config['filemanager_Max_file_size'];
20$path = $_POST['path'];
21$show_upload_boxes = count($_FILES['upload_file']['name'])-1;
22
23
24function create_summaryImage($file){
25        list($width, $height,$image_type) = getimagesize($file);
26        switch($image_type)
27        {
28        case 1:
29                $image_big = imagecreatefromgif($file);
30                break;
31        case 2:
32                $image_big = imagecreatefromjpeg($file);
33                break;
34        case 3:
35                $image_big = imagecreatefrompng($file);
36                break;
37        default:
38                return false;
39        }
40        $max_resolution = 48;
41        if ($width > $height){
42                $new_width = $max_resolution;
43                $new_height = $height*($new_width/$width);
44        }
45        else {
46                $new_height = $max_resolution;
47                $new_width = $width*($new_height/$height);
48        }
49        $image_new = imagecreatetruecolor($new_width, $new_height);
50        imagecopyresampled($image_new, $image_big, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
51        ob_start();
52        imagepng($image_new);
53        $content = ob_get_clean();
54        return $content;
55}
56
57/* Its much faster test all files only one time */
58if(strlen($current_config['filemanager_antivirus_command']) > 0)
59{
60        $command = "nice -n19 ".$current_config['filemanager_antivirus_command'];
61        for($i = 0; $i != $show_upload_boxes; $i++)
62                $command .= " ".$_FILES['upload_file']['tmp_name'][$i];
63        $return=0;
64        exec("bash -c ".escapeshellcmd(escapeshellarg($command)),$output,$return);
65        if ($return == 1)
66        {
67                $_SESSION['response'] = serialize(array(0 => lang('Error:').lang('One of the files sent was considered infected')));
68                return;
69        }
70}
71
72if($path != '/')
73        for($i = 0; $i != $show_upload_boxes; $i++)
74        {
75                if($badchar = $bo->bad_chars($_FILES['upload_file']['name'][$i], True, True))
76                {
77                        $return[] = lang('Error:').lang('File names cannot contain "%1"', $badchar);
78                        continue;
79                }
80
81                # Check to see if the file exists in the database, and get its info at the same time
82                $ls_array = $bo->vfs->ls(array(
83                        'string'=> $path . '/' . $_FILES['upload_file']['name'][$i],
84                        'relatives'     => array(RELATIVE_NONE),
85                        'checksubdirs'  => False,
86                        'nofiles'       => True
87                ));
88
89                $fileinfo = $ls_array[0];
90
91                if($fileinfo['name'])
92                {
93                        if($fileinfo['mime_type'] == 'Directory')
94                        {
95                                $return[] = lang('Error:').lang('Cannot replace %1 because it is a directory', $fileinfo['name']);
96                                continue;
97                        }
98                }
99
100                if ($_FILES['upload_file']['size'][$i] > ($upload_max_size*1024*1024))
101                {
102                        $return[] = lang('The size of %1 has exceded the limit: %2', $_FILES['upload_file']['name'][$i], $upload_max_size);
103                        continue;
104                }
105                elseif($_FILES['upload_file']['size'][$i] > 0)
106                {
107                        if($fileinfo['name'] && $fileinfo['deleteable'] != 'N')
108                        {
109                                $_FILES['upload_file']['name'][$i] = date('Ymd-H:i')."-".$_FILES['upload_file']['name'][$i];
110                                $tmp_arr=array(
111                                        'from'  => $_FILES['upload_file']['tmp_name'][$i],
112                                        'to'    => $_FILES['upload_file']['name'][$i],
113                                        'relatives'     => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL)
114
115                                );
116                                $bo->vfs->cp($tmp_arr);
117                                $tmp_arr=array(
118                                        'string'=> $_FILES['upload_file']['name'][$i],
119                                        'relatives'     => array(RELATIVE_ALL),
120                                        'attributes'    => array(
121                                                'owner_id' => $bo->userinfo['username'],
122                                                'modifiedby_id' => $bo->userinfo['username'],
123                                                'size' => $_FILES['upload_file']['size'][$i],
124                                                'mime_type' => $_FILES['upload_file']['type'][$i],
125                                                'deleteable' => 'Y',
126                                                'comment' => stripslashes($_POST['upload_comment'][$i])
127                                        )
128                                );
129                                $bo->vfs->set_attributes($tmp_arr);
130
131                                $return[] = lang("There is a file %1, that was not replaced",$_FILES['upload_file']['name'][$i]);
132                        }
133                        else
134                        {
135
136                                if ($bo->vfs->cp(array(
137                                        'from'=> $_FILES['upload_file']['tmp_name'][$i],
138                                        'to'=> $_FILES['upload_file']['name'][$i],
139                                        'relatives'     => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL)
140                                )))
141                                {
142                                        $bo->vfs->set_attributes(array(
143                                                'string'=> $_FILES['upload_file']['name'][$i],
144                                                'relatives'     => array(RELATIVE_ALL),
145                                                'attributes'=> array(
146                                                        'mime_type' => $_FILES['upload_file']['type'][$i],
147                                                        'comment' => stripslashes($_POST['upload_comment'][$i])
148                                                )
149                                        ));
150                                }
151                                else{
152                                        $return[] = lang('Error:').lang('It was not possible to send your file');
153                                }
154
155                        }
156                }
157                elseif($_FILES['upload_file']['name'][$i])
158                {
159                        $bo->vfs->touch(array(
160                                'string'=> $_FILES['upload_file']['name'][$i],
161                                'relatives'     => array(RELATIVE_ALL)
162                        ));
163
164                        $bo->vfs->set_attributes(array(
165                                'string'=> $_FILES['upload_file']['name'][$i],
166                                'relatives'     => array(RELATIVE_ALL),
167                                'attributes'=> array(
168                                        'mime_type' => $_FILES['upload_file']['type'][$i],
169                                        'comment' => stripslashes($_POST['upload_comment'][$i])
170                                )
171                        ));
172
173                }
174
175                if (!(strpos(strtoupper($_FILES['upload_file']['type'][$i]),'IMAGE') === FALSE))
176                {
177                        $content = create_summaryImage($_FILES['upload_file']['tmp_name'][$i]);
178                        if ($content){
179                                $bo->vfs->set_summary(array(
180                                        'string'=> $_FILES['upload_file']['name'][$i],
181                                        'relatives' => array(RELATIVE_ALL),
182                                        'summary'=> $content
183                                ));
184                        }
185
186                }
187        }
188if (count($return) > 0)
189                $_SESSION['response'] = serialize($return);
190        else
191                 $_SESSION['response'] = serialize( array( 0 => 'Ok' ) );
192?>
Note: See TracBrowser for help on using the repository browser.