| @@ 416-473 (lines=58) @@ | ||
| 413 | } |
|
| 414 | ||
| 415 | // Loop through $_FILES['attachment'] array and move each file to the current attachments folder. |
|
| 416 | foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) |
|
| 417 | { |
|
| 418 | if ($_FILES['attachment']['name'][$n] == '') |
|
| 419 | continue; |
|
| 420 | ||
| 421 | // First, let's first check for PHP upload errors. |
|
| 422 | $errors = array(); |
|
| 423 | if (!empty($_FILES['attachment']['error'][$n])) |
|
| 424 | { |
|
| 425 | if ($_FILES['attachment']['error'][$n] == 2) |
|
| 426 | $errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit'])); |
|
| 427 | elseif ($_FILES['attachment']['error'][$n] == 6) |
|
| 428 | log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical'); |
|
| 429 | else |
|
| 430 | log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]); |
|
| 431 | if (empty($errors)) |
|
| 432 | $errors[] = 'attach_php_error'; |
|
| 433 | } |
|
| 434 | ||
| 435 | // Try to move and rename the file before doing any more checks on it. |
|
| 436 | $attachID = 'post_tmp_' . $user_info['id'] . '_' . md5(mt_rand()); |
|
| 437 | $destName = $context['attach_dir'] . '/' . $attachID; |
|
| 438 | if (empty($errors)) |
|
| 439 | { |
|
| 440 | $_SESSION['temp_attachments'][$attachID] = array( |
|
| 441 | 'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])), |
|
| 442 | 'tmp_name' => $destName, |
|
| 443 | 'size' => $_FILES['attachment']['size'][$n], |
|
| 444 | 'type' => $_FILES['attachment']['type'][$n], |
|
| 445 | 'id_folder' => $modSettings['currentAttachmentUploadDir'], |
|
| 446 | 'errors' => array(), |
|
| 447 | ); |
|
| 448 | ||
| 449 | // Move the file to the attachments folder with a temp name for now. |
|
| 450 | if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) |
|
| 451 | @chmod($destName, 0644); |
|
| 452 | else |
|
| 453 | { |
|
| 454 | $_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout'; |
|
| 455 | if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
| 456 | unlink($_FILES['attachment']['tmp_name'][$n]); |
|
| 457 | } |
|
| 458 | } |
|
| 459 | else |
|
| 460 | { |
|
| 461 | $_SESSION['temp_attachments'][$attachID] = array( |
|
| 462 | 'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])), |
|
| 463 | 'tmp_name' => $destName, |
|
| 464 | 'errors' => $errors, |
|
| 465 | ); |
|
| 466 | ||
| 467 | if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
| 468 | unlink($_FILES['attachment']['tmp_name'][$n]); |
|
| 469 | } |
|
| 470 | // If there's no errors to this point. We still do need to apply some additional checks before we are finished. |
|
| 471 | if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) |
|
| 472 | attachmentChecks($attachID); |
|
| 473 | } |
|
| 474 | // Mod authors, finally a hook to hang an alternate attachment upload system upon |
|
| 475 | // Upload to the current attachment folder with the file name $attachID or 'post_tmp_' . $user_info['id'] . '_' . md5(mt_rand()) |
|
| 476 | // Populate $_SESSION['temp_attachments'][$attachID] with the following: |
|
| @@ 226-296 (lines=71) @@ | ||
| 223 | } |
|
| 224 | ||
| 225 | // Loop through $_FILES['attachment'] array and move each file to the current attachments folder. |
|
| 226 | foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) |
|
| 227 | { |
|
| 228 | if ($_FILES['attachment']['name'][$n] == '') |
|
| 229 | continue; |
|
| 230 | ||
| 231 | // First, let's first check for PHP upload errors. |
|
| 232 | $errors = array(); |
|
| 233 | if (!empty($_FILES['attachment']['error'][$n])) |
|
| 234 | { |
|
| 235 | if ($_FILES['attachment']['error'][$n] == 2) |
|
| 236 | $errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit'])); |
|
| 237 | ||
| 238 | else |
|
| 239 | log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]); |
|
| 240 | ||
| 241 | // Log this one, because... |
|
| 242 | if ($_FILES['attachment']['error'][$n] == 6) |
|
| 243 | log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical'); |
|
| 244 | ||
| 245 | // Weird, no errors were cached, still fill out a generic one. |
|
| 246 | if (empty($errors)) |
|
| 247 | $errors[] = 'attach_php_error'; |
|
| 248 | } |
|
| 249 | ||
| 250 | // Try to move and rename the file before doing any more checks on it. |
|
| 251 | $attachID = 'post_tmp_' . $user_info['id'] . '_' . md5(mt_rand()); |
|
| 252 | $destName = $this->_attchDir . '/' . $attachID; |
|
| 253 | ||
| 254 | // No errors, YAY! |
|
| 255 | if (empty($errors)) |
|
| 256 | { |
|
| 257 | $_SESSION['temp_attachments'][$attachID] = array( |
|
| 258 | 'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])), |
|
| 259 | 'tmp_name' => $destName, |
|
| 260 | 'size' => $_FILES['attachment']['size'][$n], |
|
| 261 | 'type' => $_FILES['attachment']['type'][$n], |
|
| 262 | 'id_folder' => $modSettings['currentAttachmentUploadDir'], |
|
| 263 | 'errors' => array(), |
|
| 264 | ); |
|
| 265 | ||
| 266 | // Move the file to the attachments folder with a temp name for now. |
|
| 267 | if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) |
|
| 268 | @chmod($destName, 0644); |
|
| 269 | ||
| 270 | // This is madness!! |
|
| 271 | else |
|
| 272 | { |
|
| 273 | // File couldn't be moved. |
|
| 274 | $_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout'; |
|
| 275 | if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
| 276 | unlink($_FILES['attachment']['tmp_name'][$n]); |
|
| 277 | } |
|
| 278 | } |
|
| 279 | ||
| 280 | // Fill up a nice array with some data from the file and the errors encountered so far. |
|
| 281 | else |
|
| 282 | { |
|
| 283 | $_SESSION['temp_attachments'][$attachID] = array( |
|
| 284 | 'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])), |
|
| 285 | 'tmp_name' => $destName, |
|
| 286 | 'errors' => $errors, |
|
| 287 | ); |
|
| 288 | ||
| 289 | if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
| 290 | unlink($_FILES['attachment']['tmp_name'][$n]); |
|
| 291 | } |
|
| 292 | ||
| 293 | // If there's no errors to this point. We still do need to apply some additional checks before we are finished. |
|
| 294 | if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) |
|
| 295 | attachmentChecks($attachID); |
|
| 296 | } |
|
| 297 | ||
| 298 | // Mod authors, finally a hook to hang an alternate attachment upload system upon |
|
| 299 | // Upload to the current attachment folder with the file name $attachID or 'post_tmp_' . $user_info['id'] . '_' . md5(mt_rand()) |
|