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

Revision 1838, 5.4 KB checked in by amuller, 15 years ago (diff)

Ticket #597 - Melhoria do FM, Imagem padrão ao buscar thumbnail

  • 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 = base64_decode($_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        imagegif($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                                $tmp_arr=array(
110                                        'string'=> $_FILES['upload_file']['name'][$i],
111                                        'relatives'     => array(RELATIVE_ALL),
112                                        'attributes'    => array(
113                                                'owner_id' => $bo->userinfo['username'],
114                                                'modifiedby_id' => $bo->userinfo['username'],
115                                                'modified' => $now,
116                                                'size' => $_FILES['upload_file']['size'][$i],
117                                                'mime_type' => $_FILES['upload_file']['type'][$i],
118                                                'deleteable' => 'Y',
119                                                'comment' => stripslashes($_POST['upload_comment'][$i])
120                                        )
121                                );
122                                $bo->vfs->set_attributes($tmp_arr);
123
124                                $tmp_arr=array(
125                                        'from'  => $_FILES['upload_file']['tmp_name'][$i],
126                                        'to'    => lang('new')."_".$_FILES['upload_file']['name'][$i],
127                                        'relatives'     => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL)
128                                );
129                                $bo->vfs->cp($tmp_arr);
130                        }
131                        else
132                        {
133               
134                                if ($bo->vfs->cp(array(
135                                        'from'=> $_FILES['upload_file']['tmp_name'][$i],
136                                        'to'=> $_FILES['upload_file']['name'][$i],
137                                        'relatives'     => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL)
138                                )))
139                                {
140                                        $bo->vfs->set_attributes(array(
141                                                'string'=> $_FILES['upload_file']['name'][$i],
142                                                'relatives'     => array(RELATIVE_ALL),
143                                                'attributes'=> array(
144                                                'mime_type' => $_FILES['upload_file']['type'][$i],
145                                                'comment' => stripslashes($_POST['upload_comment'][$i])
146                                        )
147                                ));
148                                        if (!(strpos(strtoupper($_FILES['upload_file']['type'][$i]),'IMAGE') === FALSE))
149                                        {
150                                                $content = create_summaryImage($_FILES['upload_file']['tmp_name'][$i]);
151                                                if ($content){
152                                                        $bo->vfs->set_summary(array(
153                                                        'string'=> $_FILES['upload_file']['name'][$i],
154                                                        'relatives' => array(RELATIVE_ALL),
155                                                        'summary'=> $content
156                                                        ));
157                                                }
158
159                                        }
160                                }
161                                else{
162                                        $return[] = lang('Error:').lang('Your quota has exceeded the limit');
163                                        return false;
164                                }
165
166                        }
167                }
168                elseif($_FILES['upload_file']['name'][$i])
169                {
170                        $bo->vfs->touch(array(
171                                'string'=> $_FILES['upload_file']['name'][$i],
172                                'relatives'     => array(RELATIVE_ALL)
173                        ));
174
175                        $bo->vfs->set_attributes(array(
176                                'string'=> $_FILES['upload_file']['name'][$i],
177                                'relatives'     => array(RELATIVE_ALL),
178                                'attributes'=> array(
179                                'mime_type' => $_FILES['upload_file']['type'][$i],
180                                'comment' => stripslashes($_POST['upload_comment'][$i])
181                                )
182                        ));
183
184                }
185        }
186        if (count($return) > 0)
187                $_SESSION['response'] = serialize($return);
188        else
189                 $_SESSION['response'] = serialize( array( 0 => 'Ok' ) );
190?>
Note: See TracBrowser for help on using the repository browser.