Advertisement
chisumo

Untitled

May 24th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. public function contributorUpload()
  2. {
  3. if (!($contact = $this->getActiveUser())) {
  4. throw new Exception\CoreException(
  5. 'invalid user',
  6. 'this action requires an authenticated user',
  7. 401,
  8. \Phalcon\Logger::ERROR
  9. );
  10. }
  11.  
  12. if (!($hf = $contact->getContributorHotFolder())) {
  13. $errors = $contact->getMessagesAsArray();
  14.  
  15. throw new Exception\CoreException(
  16. 'forbidden',
  17. $errors[0],
  18. 403,
  19. \Phalcon\Logger::ERROR,
  20. "contact `{$contact->idcontacts}`, ".implode('; ', $errors)
  21. );
  22. }
  23.  
  24. $myHotfolder = realpath($this->settings['coo']['contributorHotfolderRoot'] . $hf) . DIRECTORY_SEPARATOR;
  25.  
  26. if ($myHotfolder == false) {
  27. throw new Exception\CoreException(
  28. 'internal server error',
  29. 'upload folder is currently unavailable',
  30. 500,
  31. \Phalcon\Logger::ERROR,
  32. "contact `{$contact->idcontacts}`, missing upload hotfolder `{$this->settings['coo']['contributorHotfolderRoot']}{$hf}`"
  33. );
  34. }
  35.  
  36. if (($files = $this->getRequestFiles()) === false) {
  37. throw new Exception\CoreException(
  38. 'file upload failed',
  39. $this->getMessages()[0],
  40. 500,
  41. \Phalcon\Logger::ERROR,
  42. implode('; ', $this->getMessages())
  43. );
  44. }
  45.  
  46. $errors = $this->getMessages();
  47.  
  48. foreach ($files as $file) {
  49. $cleanName = General\Utils::normalizeChars($file['name']);
  50. $hotName = $myHotfolder . $cleanName;
  51.  
  52. if (file_exists($hotName)) {
  53. $dupeName = rtrim($hotName, ".{$file['extn']}");
  54. $dupeCount = count(glob($dupeName . '*'));
  55.  
  56. $hotName = $dupeName . '_' . ++$dupeCount . '.' . $file['extn'];
  57. }
  58.  
  59. $this->logger->debug(__METHOD__.'|'.__LINE__."|file `{$file['name']}`; clean `{$cleanName}`; hot `{$hotName}`");
  60.  
  61. if (!rename($file['tempfile'], $hotName)) {
  62. $errors[] = "failed to upload `{$file['name']}`";
  63. $this->logger->error(__METHOD__.'|'.__LINE__."|failed to upload `{$file['name']}`" . error_get_last()['message']);
  64. @unlink($file['tempfile']);
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement