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

Revision 5327, 8.0 KB checked in by alexandrecorreia, 12 years ago (diff)

Ticket #2260 - Sincronismo do módulo Filemanager para o trunk.

Line 
1<?php
2
3require_once '../../header.session.inc.php';
4
5$post_limit = error_get_last( );
6
7if ( preg_match( '/POST Content-Length of (\d+) bytes exceeds the limit of \d+ bytes/i', $post_limit[ 'message' ], $matches ) )
8{
9        $_SESSION['response'] =  serialize( array(
10                 'postsize' => $matches[ 1 ],
11                 'max_postsize' => ini_get( 'post_max_size' )
12        ) );
13
14        exit;
15}
16
17/* This single file is used to increase upload_max_filesize and post_max_size using .htaccess*/
18if(!isset($GLOBALS['phpgw_info'])){
19        $GLOBALS['phpgw_info']['flags'] = array(
20                'currentapp' => 'filemanager',
21                'nonavbar'   => true,
22                'noheader'   => true
23        );
24}
25require_once '../../header.inc.php';
26
27$bo = CreateObject('filemanager.bofilemanager');
28$c      = CreateObject('phpgwapi.config','filemanager');
29$c->read_repository();
30
31$current_config                 = $c->config_data;
32$upload_max_size                = $current_config['filemanager_Max_file_size'];
33$path                                   = $_POST['path'];
34$notifUser                              = $_POST['notifTo'];
35$show_upload_boxes              = count($_FILES['upload_file']['name']);
36$filesUpload                    = $_FILES['upload_file'];
37
38function create_summaryImage($file)
39{
40        list($width, $height,$image_type) = getimagesize($file);
41
42        switch($image_type)
43        {
44                case 1:
45                        $image_big = imagecreatefromgif($file);
46                        break;
47                case 2:
48                        $image_big = imagecreatefromjpeg($file);
49                        break;
50                case 3:
51                        $image_big = imagecreatefrompng($file);
52                        break;
53                default:
54                        return false;
55        }
56
57        $max_resolution = 48;
58
59        if ($width > $height)
60        {
61                $new_width = $max_resolution;
62                $new_height = $height*($new_width/$width);
63        }
64        else
65        {
66                $new_height = $max_resolution;
67                $new_width = $width*($new_height/$height);
68        }
69       
70        $image_new = imagecreatetruecolor($new_width, $new_height);
71        imagecopyresampled($image_new, $image_big, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
72        ob_start();
73        imagepng($image_new);
74        $content = ob_get_clean();
75        return $content;
76}
77
78/* Its much faster test all files only one time */
79if(strlen($current_config['filemanager_antivirus_command']) > 0)
80{
81        $command = "nice -n19 ".$current_config['filemanager_antivirus_command'];
82        for($i = 0; $i != $show_upload_boxes; $i++)
83        {
84                $command .= " ".$_FILES['upload_file']['tmp_name'][$i];
85        }
86       
87        $return = 0;
88       
89        exec("bash -c ".escapeshellcmd(escapeshellarg($command)),$output,$return);
90       
91        if ($return == 1)
92        {
93                $_SESSION['response'] = serialize(array(0 => lang('Error:').lang('One of the files sent was considered infected')));
94                return;
95        }
96}
97
98if( $path != '/' )
99{
100        $return = array( );
101        for( $i = 0; $i != $show_upload_boxes; $i++)
102        {
103                if ( $_FILES['upload_file']['error'][$i] !== 0 )
104                {
105                        $return[] = array(
106                                        "file"          => $_FILES['upload_file']['name'][$i] ,
107                                        "filesize"      => 'filesize #' . $_FILES['upload_file']['error'][$i]
108                         );
109                        continue;
110                }
111                elseif ( $_FILES['upload_file']['size'][$i] > ($upload_max_size*1024*1024) )
112                {
113                        $return[] = array(
114                                                                "file"          => $_FILES['upload_file']['name'][$i] ,
115                                                                "size"          => $_FILES['upload_file']['size'][$i] ,
116                                                                "size_max"      => ($upload_max_size*1024*1024)
117                         );
118                        continue;
119                }
120                elseif( $_FILES['upload_file']['size'][$i] > 0 )
121                {
122                        $badchar = $bo->bad_chars( $_FILES['upload_file']['name'][$i], True, True );
123
124                        if( $badchar )
125                        {
126                                $return[] = array(
127                                                                "file"          => $_FILES['upload_file']['name'][$i],
128                                                                "badchar"       => lang('File names cannot contain "%1"', $badchar)
129                                );                                     
130                                continue;
131                        }
132
133                        # Check to see if the file exists in the database, and get its info at the same time
134                        $ls_array = $bo->vfs->ls(array(
135                                                'string'=> $path . '/' . $_FILES['upload_file']['name'][$i],
136                                                'relatives'     => array(RELATIVE_NONE),
137                                                'checksubdirs'  => False,
138                                                'nofiles'       => True
139                        ));
140
141                        $fileinfo = $ls_array[0];
142
143                        if( $fileinfo['name'] )
144                        {
145                                if( $fileinfo['mime_type'] == 'Directory' )
146                                {
147                                        $return[] = array(
148                                                                                "file"          => $_FILES['upload_file']['name'][$i],
149                                                                                "directory"     => lang('Cannot replace %1 because it is a directory', $fileinfo['name'] )
150                                        );
151                                        continue;
152                                }
153                        }
154
155                        if($fileinfo['name'] && $fileinfo['deleteable'] != 'N')
156                        {
157                                $FILE_ORIGINAL = $_FILES['upload_file']['name'][$i];
158                                $_FILES['upload_file']['name'][$i] = date('Ymd-H:i')."-".$_FILES['upload_file']['name'][$i];
159                                $tmp_arr=array(
160                                        'from'  => $_FILES['upload_file']['tmp_name'][$i],
161                                        'to'    => $_FILES['upload_file']['name'][$i],
162                                        'relatives'     => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL)
163
164                                );
165                                $bo->vfs->cp($tmp_arr);
166                                $tmp_arr=array(
167                                                'string'                => $_FILES['upload_file']['name'][$i],
168                                                'relatives'             => array(RELATIVE_ALL),
169                                                'attributes'    => array(
170                                                'owner_id'              => $bo->userinfo['username'],
171                                                'modifiedby_id' => $bo->userinfo['username'],
172                                                'size'                  => $_FILES['upload_file']['size'][$i],
173                                                'mime_type'             => $_FILES['upload_file']['type'][$i],
174                                                'deleteable'    => 'Y',
175                                                'comment'               => stripslashes($_POST['upload_comment'][$i])
176                                        )
177                                );
178                                $bo->vfs->set_attributes($tmp_arr);
179
180                                $return[] = array(
181                                                                "file"          => $FILE_ORIGINAL,                                                                     
182                                                                "undefined"     => lang( "There is a file %1, that was not replaced", $FILE_ORIGINAL )
183                                );
184                        }
185                        else
186                        {
187                                if ($bo->vfs->cp(array(
188                                        'from'=> $_FILES['upload_file']['tmp_name'][$i],
189                                        'to'=> $_FILES['upload_file']['name'][$i],
190                                        'relatives'     => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL)
191                                )))
192                                {
193                                        $bo->vfs->set_attributes(array(
194                                                        'string'                => $_FILES['upload_file']['name'][$i],
195                                                        'relatives'     => array(RELATIVE_ALL),
196                                                        'attributes'    => array(
197                                                        'mime_type'     => $_FILES['upload_file']['type'][$i],
198                                                        'comment'       => stripslashes($_POST['upload_comment'][$i])
199                                                        )
200                                        ));
201                                }
202                                else
203                                {
204                                        $return[] = array (
205                                                                                "file"          => $_FILES['upload_file']['name'][$i],
206                                                                                "sendFile"      => lang('It was not possible to send your file')
207                                        );
208                                }
209                        }
210                }
211                elseif( $_FILES['upload_file']['name'][$i] )
212                {
213                        $bo->vfs->touch(array(
214                                'string'=> $_FILES['upload_file']['name'][$i],
215                                'relatives'     => array(RELATIVE_ALL)
216                        ));
217
218                        $bo->vfs->set_attributes(array(
219                                        'string'                => $_FILES['upload_file']['name'][$i],
220                                        'relatives'             => array(RELATIVE_ALL),
221                                        'attributes'    => array(
222                                        'mime_type'     => $_FILES['upload_file']['type'][$i],
223                                        'comment'       => stripslashes($_POST['upload_comment'][$i])
224                                        )
225                        ));
226                }
227
228                if ( !(strpos(strtoupper($_FILES['upload_file']['type'][$i]),'IMAGE') === FALSE ) )
229                {
230                        $content = create_summaryImage($_FILES['upload_file']['tmp_name'][$i]);
231                        if ($content)
232                        {
233                                $bo->vfs->set_summary(array(
234                                        'string'=> $_FILES['upload_file']['name'][$i],
235                                        'relatives' => array(RELATIVE_ALL),
236                                        'summary'=> $content
237                                ));
238                        }
239
240                }
241        }
242}
243
244if( count($notifUser) > 0 )
245{
246        define('PHPGW_INCLUDE_ROOT','../../');
247        define('PHPGW_API_INC','../../phpgwapi/inc');
248        include_once(PHPGW_API_INC.'/class.phpmailer.inc.php');
249        $mail = new PHPMailer();
250        $mail->IsSMTP();
251        $boemailadmin = CreateObject('emailadmin.bo');
252        $emailadmin_profile = $boemailadmin->getProfileList();
253        $emailadmin = $boemailadmin->getProfile($emailadmin_profile[0]['profileID']);
254        $mail->Host = $emailadmin['smtpServer'];
255        $mail->Port = $emailadmin['smtpPort'];
256        $mail->From = $GLOBALS['phpgw']->preferences->values['email'];
257        $mail->FromName = $GLOBALS['phpgw_info']['user']['fullname'];
258        $mail->IsHTML(true);
259       
260        foreach( $notifUser as $userMail )
261        {
262                $mail->AddAddress($userMail);
263                $mail->Subject = lang("Filemanager notification");
264               
265                $body  = "<div style='font-size: 9pt !important;'>";
266                $body .= lang("The user %1 sent the following files", "<span style='font-weight: bold;'>" . $GLOBALS['phpgw_info']['user']['fullname'] . "</span>") . "<br/><br/>";
267
268                foreach( $filesUpload['name'] as $key => $name )
269                        $body .= "<div style='font-weight: bold;'> - " . $name ." ( " . $filesUpload['type'][$key] . " )</div>";
270
271                $body  .= "<div style='margin-top:25px;'>".lang("To view the files %1", "<a href='../filemanager/index.php'>".lang("Click here")."</a>")."</div>";
272                $body  .= "</div>";
273               
274                $mail->Body = $body;
275               
276                if( !$mail->Send() )
277                {
278                        $return[] = $mail->ErrorInfo;
279                }
280        }
281       
282        unset( $filesUpload );
283       
284}
285
286$_SESSION['response'] = ( count($return) > 0 ) ? serialize($return) : serialize( array( 0 => 'Ok' ) );
287
288?>
Note: See TracBrowser for help on using the repository browser.