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

Revision 1741, 4.7 KB checked in by amuller, 15 years ago (diff)

Ticket #597 - Melhorias no módulos gerenciador de arquivos do expresso livre

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