source: trunk/filemanager/inc/upload.php @ 2362

Revision 2362, 5.9 KB checked in by amuller, 14 years ago (diff)

Ticket #1008 - Adicionando informações sobre licenças

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