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

Revision 1804, 4.2 KB checked in by amuller, 14 years ago (diff)

Ticket #597 - Melhorias no modulo gerenciador de arquivos

  • 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/* Its much faster test all files only one time */
24if(strlen($current_config['filemanager_antivirus_command']) > 0)
25{
26        $command = "nice -n19 ".$current_config['filemanager_antivirus_command'];
27        for($i = 0; $i != $show_upload_boxes; $i++)
28                $command .= " ".$_FILES['upload_file']['tmp_name'][$i];
29        $return=0;
30        exec("bash -c ".escapeshellcmd(escapeshellarg($command)),$output,$return);
31        if ($return == 1)
32        {
33                $_SESSION['response'] = serialize(array(0 => lang('Error:').lang('One of the files sent was considered infected')));
34                return;
35        }
36}
37
38if($path != '/')
39        for($i = 0; $i != $show_upload_boxes; $i++)
40        {
41                if($badchar = $bo->bad_chars($_FILES['upload_file']['name'][$i], True, True))
42                {
43                        $return[] = lang('Error:').lang('File names cannot contain "%1"', $badchar);
44                        continue;
45                }
46
47                # Check to see if the file exists in the database, and get its info at the same time
48                $ls_array = $bo->vfs->ls(array(
49                        'string'=> $path . '/' . $_FILES['upload_file']['name'][$i],
50                        'relatives'     => array(RELATIVE_NONE),
51                        'checksubdirs'  => False,
52                        'nofiles'       => True
53                ));
54
55                $fileinfo = $ls_array[0];
56
57                if($fileinfo['name'])
58                {
59                        if($fileinfo['mime_type'] == 'Directory')
60                        {
61                                $return[] = lang('Error:').lang('Cannot replace %1 because it is a directory', $fileinfo['name']);
62                                continue;
63                        }
64                }
65
66                if ($_FILES['upload_file']['size'][$i] > ($upload_max_size*1024*1024))
67                {
68                        $return[] = lang('The size of %1 has exceded the limit: %2', $_FILES['upload_file']['name'][$i], $upload_max_size);
69                        continue;
70                }
71                elseif($_FILES['upload_file']['size'][$i] > 0)
72                {
73                        if($fileinfo['name'] && $fileinfo['deleteable'] != 'N')
74                        {
75                                $tmp_arr=array(
76                                        'string'=> $_FILES['upload_file']['name'][$i],
77                                        'relatives'     => array(RELATIVE_ALL),
78                                        'attributes'    => array(
79                                                'owner_id' => $bo->userinfo['username'],
80                                                'modifiedby_id' => $bo->userinfo['username'],
81                                                'modified' => $now,
82                                                'size' => $_FILES['upload_file']['size'][$i],
83                                                'mime_type' => $_FILES['upload_file']['type'][$i],
84                                                'deleteable' => 'Y',
85                                                'comment' => stripslashes($_POST['upload_comment'][$i])
86                                        )
87                                );
88                                $bo->vfs->set_attributes($tmp_arr);
89
90                                $tmp_arr=array(
91                                        'from'  => $_FILES['upload_file']['tmp_name'][$i],
92                                        'to'    => lang('new')."_".$_FILES['upload_file']['name'][$i],
93                                        'relatives'     => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL)
94                                );
95                                $bo->vfs->cp($tmp_arr);
96                        }
97                        else
98                        {
99
100                                if ($bo->vfs->cp(array(
101                                        'from'=> $_FILES['upload_file']['tmp_name'][$i],
102                                        'to'=> $_FILES['upload_file']['name'][$i],
103                                        'relatives'     => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL)
104                                )))
105                                        $bo->vfs->set_attributes(array(
106                                                'string'=> $_FILES['upload_file']['name'][$i],
107                                                'relatives'     => array(RELATIVE_ALL),
108                                                'attributes'=> array(
109                                                'mime_type' => $_FILES['upload_file']['type'][$i],
110                                                'comment' => stripslashes($_POST['upload_comment'][$i])
111                                        )
112                                ));
113                                else{
114                                        $return[] = lang('Error:').lang('Your quota has exceeded the limit');
115                                        return false;
116                                }
117
118                        }
119                }
120                elseif($_FILES['upload_file']['name'][$i])
121                {
122                        $bo->vfs->touch(array(
123                                'string'=> $_FILES['upload_file']['name'][$i],
124                                'relatives'     => array(RELATIVE_ALL)
125                        ));
126
127                        $bo->vfs->set_attributes(array(
128                                'string'=> $_FILES['upload_file']['name'][$i],
129                                'relatives'     => array(RELATIVE_ALL),
130                                'attributes'=> array(
131                                        'mime_type' => $_FILES['upload_file']['type'][$i],
132                                        'comment' => stripslashes($_POST['upload_comment'][$i])
133                                )
134                        ));
135
136                }
137        }
138        if (count($return) > 0)
139                $_SESSION['response'] = serialize($return);
140        else
141                 $_SESSION['response'] = serialize( array( 0 => 'Ok' ) );
142?>
Note: See TracBrowser for help on using the repository browser.