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

Revision 1745, 4.7 KB checked in by amuller, 14 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 = 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['phpgw_info']['filemanager']['user']['messages'][] = 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                        $_SESSION['phpgw_info']['filemanager']['user']['messages'][] = 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                                $_SESSION['phpgw_info']['filemanager']['user']['messages'][] = 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                        $_SESSION['phpgw_info']['filemanager']['user']['messages'][] = 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                                $_SESSION['phpgw_info']['filemanager']['user']['messages'][] = lang('Created new %1', $_FILES['upload_file']['name'][$i])."\n";
98                        }
99                        else
100                        {
101
102                                if ($bo->vfs->cp(array(
103                                        'from'=> $_FILES['upload_file']['tmp_name'][$i],
104                                        'to'=> $_FILES['upload_file']['name'][$i],
105                                        'relatives'     => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL)
106                                )))
107                                        $bo->vfs->set_attributes(array(
108                                                'string'=> $_FILES['upload_file']['name'][$i],
109                                                'relatives'     => array(RELATIVE_ALL),
110                                                'attributes'=> array(
111                                                'mime_type' => $_FILES['upload_file']['type'][$i],
112                                                'comment' => stripslashes($_POST['upload_comment'][$i])
113                                        )
114                                ));
115                                else{
116                                        $_SESSION['phpgw_info']['filemanager']['user']['messages'][] = lang('Error:').lang('Your quota has exceeded the limit');
117                                        return false;
118                                }
119
120                                 $_SESSION['phpgw_info']['filemanager']['user']['messages'][] = lang('Created %1,%2', $_FILES['upload_file']['name'][$i], $bo->borkb($_FILES['upload_file']['size'][$i]))."\n";
121                        }
122                }
123                elseif($_FILES['upload_file']['name'][$i])
124                {
125                        $bo->vfs->touch(array(
126                                'string'=> $_FILES['upload_file']['name'][$i],
127                                'relatives'     => array(RELATIVE_ALL)
128                        ));
129
130                        $bo->vfs->set_attributes(array(
131                                'string'=> $_FILES['upload_file']['name'][$i],
132                                'relatives'     => array(RELATIVE_ALL),
133                                'attributes'=> array(
134                                        'mime_type' => $_FILES['upload_file']['type'][$i],
135                                        'comment' => stripslashes($_POST['upload_comment'][$i])
136                                )
137                        ));
138
139                         $_SESSION['phpgw_info']['filemanager']['user']['messages'][] = lang('Created %1,%2', $_FILES['upload_file']['name'][$i], $bo->borkb($file_size[$i]))."\n";
140
141                }
142        }
143?>
Note: See TracBrowser for help on using the repository browser.