[3019] | 1 | <?php |
---|
[3610] | 2 | |
---|
[3019] | 3 | require_once '../../header.session.inc.php'; |
---|
[3610] | 4 | |
---|
[3889] | 5 | $post_limit = error_get_last( ); |
---|
| 6 | |
---|
| 7 | if ( preg_match( '/POST Content-Length of (\d+) bytes exceeds the limit of \d+ bytes/i', $post_limit[ 'message' ], $matches ) ) |
---|
| 8 | { |
---|
| 9 | $_SESSION['response'] = serialize( array( |
---|
| 10 | 'postsize' => $matches[ 1 ], |
---|
| 11 | 'max_postsize' => ini_get( 'post_max_size' ) |
---|
| 12 | ) ); |
---|
[3896] | 13 | |
---|
[3889] | 14 | exit; |
---|
| 15 | } |
---|
| 16 | |
---|
[3019] | 17 | /* This single file is used to increase upload_max_filesize and post_max_size using .htaccess*/ |
---|
| 18 | if(!isset($GLOBALS['phpgw_info'])){ |
---|
| 19 | $GLOBALS['phpgw_info']['flags'] = array( |
---|
| 20 | 'currentapp' => 'filemanager', |
---|
| 21 | 'nonavbar' => true, |
---|
| 22 | 'noheader' => true |
---|
| 23 | ); |
---|
| 24 | } |
---|
| 25 | require_once '../../header.inc.php'; |
---|
| 26 | |
---|
| 27 | $bo = CreateObject('filemanager.bofilemanager'); |
---|
[3879] | 28 | $c = CreateObject('phpgwapi.config','filemanager'); |
---|
[3019] | 29 | $c->read_repository(); |
---|
| 30 | |
---|
[3879] | 31 | $current_config = $c->config_data; |
---|
| 32 | $upload_max_size = $current_config['filemanager_Max_file_size']; |
---|
| 33 | $path = $_POST['path']; |
---|
| 34 | $notifUser = $_POST['notifTo']; |
---|
[4915] | 35 | $show_upload_boxes = count($_FILES['upload_file']['name']); |
---|
| 36 | $filesUpload = $_FILES['upload_file']; |
---|
[3879] | 37 | |
---|
[3610] | 38 | function create_summaryImage($file) |
---|
| 39 | { |
---|
[3019] | 40 | list($width, $height,$image_type) = getimagesize($file); |
---|
[3610] | 41 | |
---|
[3019] | 42 | switch($image_type) |
---|
| 43 | { |
---|
[3610] | 44 | case 1: |
---|
| 45 | $image_big = imagecreatefromgif($file); |
---|
| 46 | break; |
---|
| 47 | case 2: |
---|
| 48 | $image_big = imagecreatefromjpeg($file); |
---|
| 49 | break; |
---|
| 50 | case 3: |
---|
| 51 | $image_big = imagecreatefrompng($file); |
---|
| 52 | break; |
---|
| 53 | default: |
---|
| 54 | return false; |
---|
[3019] | 55 | } |
---|
[3610] | 56 | |
---|
[3019] | 57 | $max_resolution = 48; |
---|
[3610] | 58 | |
---|
| 59 | if ($width > $height) |
---|
| 60 | { |
---|
[3019] | 61 | $new_width = $max_resolution; |
---|
| 62 | $new_height = $height*($new_width/$width); |
---|
| 63 | } |
---|
[3610] | 64 | else |
---|
| 65 | { |
---|
[3019] | 66 | $new_height = $max_resolution; |
---|
| 67 | $new_width = $width*($new_height/$height); |
---|
| 68 | } |
---|
[3610] | 69 | |
---|
[3019] | 70 | $image_new = imagecreatetruecolor($new_width, $new_height); |
---|
| 71 | imagecopyresampled($image_new, $image_big, 0, 0, 0, 0, $new_width, $new_height, $width, $height); |
---|
| 72 | ob_start(); |
---|
| 73 | imagepng($image_new); |
---|
| 74 | $content = ob_get_clean(); |
---|
| 75 | return $content; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | /* Its much faster test all files only one time */ |
---|
| 79 | if(strlen($current_config['filemanager_antivirus_command']) > 0) |
---|
| 80 | { |
---|
| 81 | $command = "nice -n19 ".$current_config['filemanager_antivirus_command']; |
---|
| 82 | for($i = 0; $i != $show_upload_boxes; $i++) |
---|
[3610] | 83 | { |
---|
[3019] | 84 | $command .= " ".$_FILES['upload_file']['tmp_name'][$i]; |
---|
[3610] | 85 | } |
---|
| 86 | |
---|
| 87 | $return = 0; |
---|
| 88 | |
---|
[3019] | 89 | exec("bash -c ".escapeshellcmd(escapeshellarg($command)),$output,$return); |
---|
[3610] | 90 | |
---|
[3019] | 91 | if ($return == 1) |
---|
| 92 | { |
---|
| 93 | $_SESSION['response'] = serialize(array(0 => lang('Error:').lang('One of the files sent was considered infected'))); |
---|
| 94 | return; |
---|
| 95 | } |
---|
| 96 | } |
---|
| 97 | |
---|
[3879] | 98 | if( $path != '/' ) |
---|
[3610] | 99 | { |
---|
[3889] | 100 | $return = array( ); |
---|
[3879] | 101 | for( $i = 0; $i != $show_upload_boxes; $i++) |
---|
[3019] | 102 | { |
---|
[3889] | 103 | if ( $_FILES['upload_file']['error'][$i] !== 0 ) |
---|
[3019] | 104 | { |
---|
[3879] | 105 | $return[] = array( |
---|
[3889] | 106 | "file" => $_FILES['upload_file']['name'][$i] , |
---|
| 107 | "filesize" => 'filesize #' . $_FILES['upload_file']['error'][$i] |
---|
| 108 | ); |
---|
| 109 | continue; |
---|
| 110 | } |
---|
| 111 | elseif ( $_FILES['upload_file']['size'][$i] > ($upload_max_size*1024*1024) ) |
---|
| 112 | { |
---|
| 113 | $return[] = array( |
---|
[3879] | 114 | "file" => $_FILES['upload_file']['name'][$i] , |
---|
| 115 | "size" => $_FILES['upload_file']['size'][$i] , |
---|
| 116 | "size_max" => ($upload_max_size*1024*1024) |
---|
| 117 | ); |
---|
[3019] | 118 | continue; |
---|
| 119 | } |
---|
[3879] | 120 | elseif( $_FILES['upload_file']['size'][$i] > 0 ) |
---|
| 121 | { |
---|
[3881] | 122 | $badchar = $bo->bad_chars( $_FILES['upload_file']['name'][$i], True, True ); |
---|
[4915] | 123 | |
---|
[3881] | 124 | if( $badchar ) |
---|
[3879] | 125 | { |
---|
| 126 | $return[] = array( |
---|
| 127 | "file" => $_FILES['upload_file']['name'][$i], |
---|
| 128 | "badchar" => lang('File names cannot contain "%1"', $badchar) |
---|
| 129 | ); |
---|
| 130 | continue; |
---|
| 131 | } |
---|
[3019] | 132 | |
---|
[3879] | 133 | # Check to see if the file exists in the database, and get its info at the same time |
---|
| 134 | $ls_array = $bo->vfs->ls(array( |
---|
| 135 | 'string'=> $path . '/' . $_FILES['upload_file']['name'][$i], |
---|
| 136 | 'relatives' => array(RELATIVE_NONE), |
---|
| 137 | 'checksubdirs' => False, |
---|
| 138 | 'nofiles' => True |
---|
| 139 | )); |
---|
[3019] | 140 | |
---|
[3879] | 141 | $fileinfo = $ls_array[0]; |
---|
[3019] | 142 | |
---|
[3879] | 143 | if( $fileinfo['name'] ) |
---|
[3019] | 144 | { |
---|
[3879] | 145 | if( $fileinfo['mime_type'] == 'Directory' ) |
---|
| 146 | { |
---|
| 147 | $return[] = array( |
---|
| 148 | "file" => $_FILES['upload_file']['name'][$i], |
---|
| 149 | "directory" => lang('Cannot replace %1 because it is a directory', $fileinfo['name'] ) |
---|
| 150 | ); |
---|
| 151 | continue; |
---|
| 152 | } |
---|
[3019] | 153 | } |
---|
| 154 | |
---|
| 155 | if($fileinfo['name'] && $fileinfo['deleteable'] != 'N') |
---|
| 156 | { |
---|
[3896] | 157 | $FILE_ORIGINAL = $_FILES['upload_file']['name'][$i]; |
---|
[3019] | 158 | $_FILES['upload_file']['name'][$i] = date('Ymd-H:i')."-".$_FILES['upload_file']['name'][$i]; |
---|
| 159 | $tmp_arr=array( |
---|
| 160 | 'from' => $_FILES['upload_file']['tmp_name'][$i], |
---|
| 161 | 'to' => $_FILES['upload_file']['name'][$i], |
---|
| 162 | 'relatives' => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL) |
---|
| 163 | |
---|
| 164 | ); |
---|
| 165 | $bo->vfs->cp($tmp_arr); |
---|
| 166 | $tmp_arr=array( |
---|
[4915] | 167 | 'string' => $_FILES['upload_file']['name'][$i], |
---|
| 168 | 'relatives' => array(RELATIVE_ALL), |
---|
[3879] | 169 | 'attributes' => array( |
---|
[4915] | 170 | 'owner_id' => $bo->userinfo['username'], |
---|
| 171 | 'modifiedby_id' => $bo->userinfo['username'], |
---|
| 172 | 'size' => $_FILES['upload_file']['size'][$i], |
---|
| 173 | 'mime_type' => $_FILES['upload_file']['type'][$i], |
---|
| 174 | 'deleteable' => 'Y', |
---|
| 175 | 'comment' => stripslashes($_POST['upload_comment'][$i]) |
---|
[3019] | 176 | ) |
---|
| 177 | ); |
---|
| 178 | $bo->vfs->set_attributes($tmp_arr); |
---|
| 179 | |
---|
[3879] | 180 | $return[] = array( |
---|
[3897] | 181 | "file" => $FILE_ORIGINAL, |
---|
[3896] | 182 | "undefined" => lang( "There is a file %1, that was not replaced", $FILE_ORIGINAL ) |
---|
[3879] | 183 | ); |
---|
[3019] | 184 | } |
---|
| 185 | else |
---|
| 186 | { |
---|
| 187 | if ($bo->vfs->cp(array( |
---|
| 188 | 'from'=> $_FILES['upload_file']['tmp_name'][$i], |
---|
| 189 | 'to'=> $_FILES['upload_file']['name'][$i], |
---|
| 190 | 'relatives' => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL) |
---|
| 191 | ))) |
---|
| 192 | { |
---|
[4915] | 193 | $bo->vfs->set_attributes(array( |
---|
[3879] | 194 | 'string' => $_FILES['upload_file']['name'][$i], |
---|
| 195 | 'relatives' => array(RELATIVE_ALL), |
---|
| 196 | 'attributes' => array( |
---|
[4915] | 197 | 'mime_type' => $_FILES['upload_file']['type'][$i], |
---|
| 198 | 'comment' => stripslashes($_POST['upload_comment'][$i]) |
---|
[3879] | 199 | ) |
---|
[3019] | 200 | )); |
---|
| 201 | } |
---|
[3879] | 202 | else |
---|
| 203 | { |
---|
| 204 | $return[] = array ( |
---|
| 205 | "file" => $_FILES['upload_file']['name'][$i], |
---|
| 206 | "sendFile" => lang('It was not possible to send your file') |
---|
| 207 | ); |
---|
[3019] | 208 | } |
---|
| 209 | } |
---|
| 210 | } |
---|
[3879] | 211 | elseif( $_FILES['upload_file']['name'][$i] ) |
---|
[3019] | 212 | { |
---|
| 213 | $bo->vfs->touch(array( |
---|
| 214 | 'string'=> $_FILES['upload_file']['name'][$i], |
---|
| 215 | 'relatives' => array(RELATIVE_ALL) |
---|
| 216 | )); |
---|
| 217 | |
---|
| 218 | $bo->vfs->set_attributes(array( |
---|
[3879] | 219 | 'string' => $_FILES['upload_file']['name'][$i], |
---|
[4915] | 220 | 'relatives' => array(RELATIVE_ALL), |
---|
[3879] | 221 | 'attributes' => array( |
---|
[4915] | 222 | 'mime_type' => $_FILES['upload_file']['type'][$i], |
---|
| 223 | 'comment' => stripslashes($_POST['upload_comment'][$i]) |
---|
[3879] | 224 | ) |
---|
[3019] | 225 | )); |
---|
| 226 | } |
---|
| 227 | |
---|
[3879] | 228 | if ( !(strpos(strtoupper($_FILES['upload_file']['type'][$i]),'IMAGE') === FALSE ) ) |
---|
[3019] | 229 | { |
---|
| 230 | $content = create_summaryImage($_FILES['upload_file']['tmp_name'][$i]); |
---|
[3879] | 231 | if ($content) |
---|
| 232 | { |
---|
[3019] | 233 | $bo->vfs->set_summary(array( |
---|
| 234 | 'string'=> $_FILES['upload_file']['name'][$i], |
---|
| 235 | 'relatives' => array(RELATIVE_ALL), |
---|
| 236 | 'summary'=> $content |
---|
| 237 | )); |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | } |
---|
| 241 | } |
---|
[3610] | 242 | } |
---|
[3415] | 243 | |
---|
[3610] | 244 | if( count($notifUser) > 0 ) |
---|
[3415] | 245 | { |
---|
| 246 | define('PHPGW_INCLUDE_ROOT','../../'); |
---|
| 247 | define('PHPGW_API_INC','../../phpgwapi/inc'); |
---|
| 248 | include_once(PHPGW_API_INC.'/class.phpmailer.inc.php'); |
---|
| 249 | $mail = new PHPMailer(); |
---|
| 250 | $mail->IsSMTP(); |
---|
| 251 | $boemailadmin = CreateObject('emailadmin.bo'); |
---|
| 252 | $emailadmin_profile = $boemailadmin->getProfileList(); |
---|
| 253 | $emailadmin = $boemailadmin->getProfile($emailadmin_profile[0]['profileID']); |
---|
| 254 | $mail->Host = $emailadmin['smtpServer']; |
---|
| 255 | $mail->Port = $emailadmin['smtpPort']; |
---|
| 256 | $mail->From = $GLOBALS['phpgw']->preferences->values['email']; |
---|
| 257 | $mail->FromName = $GLOBALS['phpgw_info']['user']['fullname']; |
---|
| 258 | $mail->IsHTML(true); |
---|
[3610] | 259 | |
---|
| 260 | foreach( $notifUser as $userMail ) |
---|
[3415] | 261 | { |
---|
| 262 | $mail->AddAddress($userMail); |
---|
| 263 | $mail->Subject = lang("Filemanager notification"); |
---|
[3610] | 264 | |
---|
| 265 | $body = "<div style='font-size: 9pt !important;'>"; |
---|
| 266 | $body .= lang("The user %1 sent the following files", "<span style='font-weight: bold;'>" . $GLOBALS['phpgw_info']['user']['fullname'] . "</span>") . "<br/><br/>"; |
---|
| 267 | |
---|
| 268 | foreach( $filesUpload['name'] as $key => $name ) |
---|
| 269 | $body .= "<div style='font-weight: bold;'> - " . $name ." ( " . $filesUpload['type'][$key] . " )</div>"; |
---|
| 270 | |
---|
| 271 | $body .= "<div style='margin-top:25px;'>".lang("To view the files %1", "<a href='../filemanager/index.php'>".lang("Click here")."</a>")."</div>"; |
---|
| 272 | $body .= "</div>"; |
---|
| 273 | |
---|
| 274 | $mail->Body = $body; |
---|
| 275 | |
---|
| 276 | if( !$mail->Send() ) |
---|
| 277 | { |
---|
[3415] | 278 | $return[] = $mail->ErrorInfo; |
---|
| 279 | } |
---|
| 280 | } |
---|
[3610] | 281 | |
---|
| 282 | unset( $filesUpload ); |
---|
| 283 | |
---|
[3415] | 284 | } |
---|
| 285 | |
---|
[3610] | 286 | $_SESSION['response'] = ( count($return) > 0 ) ? serialize($return) : serialize( array( 0 => 'Ok' ) ); |
---|
| 287 | |
---|
| 288 | ?> |
---|