[1693] | 1 | <?php |
---|
| 2 | require_once '../../header.session.inc.php'; |
---|
| 3 | |
---|
| 4 | /* This single file is used to increase upload_max_filesize and post_max_size using .htaccess*/ |
---|
| 5 | if(!isset($GLOBALS['phpgw_info'])){ |
---|
| 6 | $GLOBALS['phpgw_info']['flags'] = array( |
---|
| 7 | 'currentapp' => 'filemanager', |
---|
| 8 | 'nonavbar' => true, |
---|
| 9 | 'noheader' => true |
---|
| 10 | ); |
---|
| 11 | } |
---|
| 12 | require_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']; |
---|
[1869] | 20 | $path = $_POST['path']; |
---|
[1745] | 21 | $show_upload_boxes = count($_FILES['upload_file']['name'])-1; |
---|
[1693] | 22 | |
---|
[1829] | 23 | |
---|
| 24 | function create_summaryImage($file){ |
---|
| 25 | list($width, $height,$image_type) = getimagesize($file); |
---|
| 26 | switch($image_type) |
---|
| 27 | { |
---|
| 28 | case 1: |
---|
| 29 | $image_big = imagecreatefromgif($file); |
---|
| 30 | break; |
---|
| 31 | case 2: |
---|
| 32 | $image_big = imagecreatefromjpeg($file); |
---|
| 33 | break; |
---|
| 34 | case 3: |
---|
| 35 | $image_big = imagecreatefrompng($file); |
---|
| 36 | break; |
---|
| 37 | default: |
---|
[1838] | 38 | return false; |
---|
[1829] | 39 | } |
---|
| 40 | $max_resolution = 48; |
---|
| 41 | if ($width > $height){ |
---|
| 42 | $new_width = $max_resolution; |
---|
| 43 | $new_height = $height*($new_width/$width); |
---|
| 44 | } |
---|
| 45 | else { |
---|
| 46 | $new_height = $max_resolution; |
---|
| 47 | $new_width = $width*($new_height/$height); |
---|
| 48 | } |
---|
| 49 | $image_new = imagecreatetruecolor($new_width, $new_height); |
---|
| 50 | imagecopyresampled($image_new, $image_big, 0, 0, 0, 0, $new_width, $new_height, $width, $height); |
---|
| 51 | ob_start(); |
---|
| 52 | imagegif($image_new); |
---|
| 53 | $content = ob_get_clean(); |
---|
| 54 | return $content; |
---|
| 55 | } |
---|
| 56 | |
---|
[1745] | 57 | /* Its much faster test all files only one time */ |
---|
| 58 | if(strlen($current_config['filemanager_antivirus_command']) > 0) |
---|
| 59 | { |
---|
| 60 | $command = "nice -n19 ".$current_config['filemanager_antivirus_command']; |
---|
| 61 | for($i = 0; $i != $show_upload_boxes; $i++) |
---|
| 62 | $command .= " ".$_FILES['upload_file']['tmp_name'][$i]; |
---|
| 63 | $return=0; |
---|
| 64 | exec("bash -c ".escapeshellcmd(escapeshellarg($command)),$output,$return); |
---|
| 65 | if ($return == 1) |
---|
| 66 | { |
---|
[1804] | 67 | $_SESSION['response'] = serialize(array(0 => lang('Error:').lang('One of the files sent was considered infected'))); |
---|
[1745] | 68 | return; |
---|
| 69 | } |
---|
| 70 | } |
---|
| 71 | |
---|
[1693] | 72 | if($path != '/') |
---|
| 73 | for($i = 0; $i != $show_upload_boxes; $i++) |
---|
| 74 | { |
---|
| 75 | if($badchar = $bo->bad_chars($_FILES['upload_file']['name'][$i], True, True)) |
---|
| 76 | { |
---|
[1804] | 77 | $return[] = lang('Error:').lang('File names cannot contain "%1"', $badchar); |
---|
[1694] | 78 | continue; |
---|
[1693] | 79 | } |
---|
| 80 | |
---|
| 81 | # Check to see if the file exists in the database, and get its info at the same time |
---|
| 82 | $ls_array = $bo->vfs->ls(array( |
---|
| 83 | 'string'=> $path . '/' . $_FILES['upload_file']['name'][$i], |
---|
| 84 | 'relatives' => array(RELATIVE_NONE), |
---|
| 85 | 'checksubdirs' => False, |
---|
| 86 | 'nofiles' => True |
---|
| 87 | )); |
---|
| 88 | |
---|
| 89 | $fileinfo = $ls_array[0]; |
---|
| 90 | |
---|
| 91 | if($fileinfo['name']) |
---|
| 92 | { |
---|
| 93 | if($fileinfo['mime_type'] == 'Directory') |
---|
| 94 | { |
---|
[1804] | 95 | $return[] = lang('Error:').lang('Cannot replace %1 because it is a directory', $fileinfo['name']); |
---|
[1694] | 96 | continue; |
---|
[1693] | 97 | } |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | if ($_FILES['upload_file']['size'][$i] > ($upload_max_size*1024*1024)) |
---|
| 101 | { |
---|
[1804] | 102 | $return[] = lang('The size of %1 has exceded the limit: %2', $_FILES['upload_file']['name'][$i], $upload_max_size); |
---|
[1694] | 103 | continue; |
---|
[1693] | 104 | } |
---|
[1745] | 105 | elseif($_FILES['upload_file']['size'][$i] > 0) |
---|
[1693] | 106 | { |
---|
| 107 | if($fileinfo['name'] && $fileinfo['deleteable'] != 'N') |
---|
| 108 | { |
---|
[1869] | 109 | $_FILES['upload_file']['name'][$i] = date('Ymd-H:i')."-".$_FILES['upload_file']['name'][$i]; |
---|
[1693] | 110 | $tmp_arr=array( |
---|
[1869] | 111 | 'from' => $_FILES['upload_file']['tmp_name'][$i], |
---|
| 112 | 'to' => $_FILES['upload_file']['name'][$i], |
---|
| 113 | 'relatives' => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL) |
---|
| 114 | |
---|
| 115 | ); |
---|
| 116 | $bo->vfs->cp($tmp_arr); |
---|
| 117 | $tmp_arr=array( |
---|
[1693] | 118 | 'string'=> $_FILES['upload_file']['name'][$i], |
---|
| 119 | 'relatives' => array(RELATIVE_ALL), |
---|
| 120 | 'attributes' => array( |
---|
| 121 | 'owner_id' => $bo->userinfo['username'], |
---|
| 122 | 'modifiedby_id' => $bo->userinfo['username'], |
---|
| 123 | 'size' => $_FILES['upload_file']['size'][$i], |
---|
| 124 | 'mime_type' => $_FILES['upload_file']['type'][$i], |
---|
| 125 | 'deleteable' => 'Y', |
---|
| 126 | 'comment' => stripslashes($_POST['upload_comment'][$i]) |
---|
| 127 | ) |
---|
| 128 | ); |
---|
| 129 | $bo->vfs->set_attributes($tmp_arr); |
---|
| 130 | |
---|
[1869] | 131 | $return[] = lang("There is a file %1, that was not replaced",$_FILES['upload_file']['name'][$i]); |
---|
[1693] | 132 | } |
---|
| 133 | else |
---|
| 134 | { |
---|
[1869] | 135 | |
---|
[1741] | 136 | if ($bo->vfs->cp(array( |
---|
[1693] | 137 | 'from'=> $_FILES['upload_file']['tmp_name'][$i], |
---|
| 138 | 'to'=> $_FILES['upload_file']['name'][$i], |
---|
| 139 | 'relatives' => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL) |
---|
[1741] | 140 | ))) |
---|
[1829] | 141 | { |
---|
[1741] | 142 | $bo->vfs->set_attributes(array( |
---|
| 143 | 'string'=> $_FILES['upload_file']['name'][$i], |
---|
| 144 | 'relatives' => array(RELATIVE_ALL), |
---|
| 145 | 'attributes'=> array( |
---|
[1869] | 146 | 'mime_type' => $_FILES['upload_file']['type'][$i], |
---|
| 147 | 'comment' => stripslashes($_POST['upload_comment'][$i]) |
---|
| 148 | ) |
---|
| 149 | )); |
---|
[1829] | 150 | } |
---|
[1741] | 151 | else{ |
---|
[1804] | 152 | $return[] = lang('Error:').lang('Your quota has exceeded the limit'); |
---|
[1741] | 153 | return false; |
---|
| 154 | } |
---|
[1693] | 155 | |
---|
| 156 | } |
---|
| 157 | } |
---|
| 158 | elseif($_FILES['upload_file']['name'][$i]) |
---|
| 159 | { |
---|
| 160 | $bo->vfs->touch(array( |
---|
| 161 | 'string'=> $_FILES['upload_file']['name'][$i], |
---|
| 162 | 'relatives' => array(RELATIVE_ALL) |
---|
| 163 | )); |
---|
| 164 | |
---|
| 165 | $bo->vfs->set_attributes(array( |
---|
| 166 | 'string'=> $_FILES['upload_file']['name'][$i], |
---|
| 167 | 'relatives' => array(RELATIVE_ALL), |
---|
| 168 | 'attributes'=> array( |
---|
[1869] | 169 | 'mime_type' => $_FILES['upload_file']['type'][$i], |
---|
| 170 | 'comment' => stripslashes($_POST['upload_comment'][$i]) |
---|
[1693] | 171 | ) |
---|
| 172 | )); |
---|
| 173 | |
---|
| 174 | } |
---|
[1869] | 175 | |
---|
| 176 | if (!(strpos(strtoupper($_FILES['upload_file']['type'][$i]),'IMAGE') === FALSE)) |
---|
| 177 | { |
---|
| 178 | $content = create_summaryImage($_FILES['upload_file']['tmp_name'][$i]); |
---|
| 179 | if ($content){ |
---|
| 180 | $bo->vfs->set_summary(array( |
---|
| 181 | 'string'=> $_FILES['upload_file']['name'][$i], |
---|
| 182 | 'relatives' => array(RELATIVE_ALL), |
---|
| 183 | 'summary'=> $content |
---|
| 184 | )); |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | } |
---|
[1693] | 188 | } |
---|
[1869] | 189 | if (count($return) > 0) |
---|
[1804] | 190 | $_SESSION['response'] = serialize($return); |
---|
| 191 | else |
---|
| 192 | $_SESSION['response'] = serialize( array( 0 => 'Ok' ) ); |
---|
[1693] | 193 | ?> |
---|