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

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

Ticket #597 - melhorias no modulo gerenciador de arquivos para arquivos grandes

  • 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['response'] = lang('Error:').lang('File names cannot contain "%1"', $badchar);
29                        return;
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['response'] = lang('Error:').lang('Cannot replace %1 because it is a directory', $fileinfo['name']);
47                                return;
48                        }
49                }
50
51                if ($_FILES['upload_file']['size'][$i] > ($upload_max_size*1024*1024))
52                {
53                        $_SESSION['response'] = lang('The size of %1 has exceded the limit: %2', $_FILES['upload_file']['name'][$i], $upload_max_size);
54                        return;
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['response'] = lang('Error:').lang('The file %1 sent was considered infected',$_FILES['upload_file']['name'][$i]);
63                                return;
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['response'] .= lang('Created new %1', $_FILES['upload_file']['name'][$i])."\n";
93                        }
94                        else
95                        {
96
97                                $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
103                                $bo->vfs->set_attributes(array(
104                                        'string'=> $_FILES['upload_file']['name'][$i],
105                                        'relatives'     => array(RELATIVE_ALL),
106                                        'attributes'=> array(
107                                                'mime_type' => $_FILES['upload_file']['type'][$i],
108                                                'comment' => stripslashes($_POST['upload_comment'][$i])
109                                        )
110                                ));
111
112                                 $_SESSION['response'] .= lang('Created %1,%2', $_FILES['upload_file']['name'][$i], $_FILES['upload_file']['size'][$i])."\n";
113                        }
114                }
115                elseif($_FILES['upload_file']['name'][$i])
116                {
117                        $bo->vfs->touch(array(
118                                'string'=> $_FILES['upload_file']['name'][$i],
119                                'relatives'     => array(RELATIVE_ALL)
120                        ));
121
122                        $bo->vfs->set_attributes(array(
123                                'string'=> $_FILES['upload_file']['name'][$i],
124                                'relatives'     => array(RELATIVE_ALL),
125                                'attributes'=> array(
126                                        'mime_type' => $_FILES['upload_file']['type'][$i],
127                                        'comment' => stripslashes($_POST['upload_comment'][$i])
128                                )
129                        ));
130
131                         $_SESSION['response'] .= lang('Created %1,%2', $_FILES['upload_file']['name'][$i], $file_size[$i])."\n";
132                }
133        }
134?>
Note: See TracBrowser for help on using the repository browser.