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

Revision 1997, 5.5 KB checked in by fpcorrea, 14 years ago (diff)

Ticket #597 - Implementada paginação e correção de bugs

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