Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function contributorUpload()
- {
- if (!($contact = $this->getActiveUser())) {
- throw new Exception\CoreException(
- 'invalid user',
- 'this action requires an authenticated user',
- 401,
- \Phalcon\Logger::ERROR
- );
- }
- if (!($hf = $contact->getContributorHotFolder())) {
- $errors = $contact->getMessagesAsArray();
- throw new Exception\CoreException(
- 'forbidden',
- $errors[0],
- 403,
- \Phalcon\Logger::ERROR,
- "contact `{$contact->idcontacts}`, ".implode('; ', $errors)
- );
- }
- $myHotfolder = realpath($this->settings['coo']['contributorHotfolderRoot'] . $hf) . DIRECTORY_SEPARATOR;
- if ($myHotfolder == false) {
- throw new Exception\CoreException(
- 'internal server error',
- 'upload folder is currently unavailable',
- 500,
- \Phalcon\Logger::ERROR,
- "contact `{$contact->idcontacts}`, missing upload hotfolder `{$this->settings['coo']['contributorHotfolderRoot']}{$hf}`"
- );
- }
- if (($files = $this->getRequestFiles()) === false) {
- throw new Exception\CoreException(
- 'file upload failed',
- $this->getMessages()[0],
- 500,
- \Phalcon\Logger::ERROR,
- implode('; ', $this->getMessages())
- );
- }
- $errors = $this->getMessages();
- foreach ($files as $file) {
- $cleanName = General\Utils::normalizeChars($file['name']);
- $hotName = $myHotfolder . $cleanName;
- if (file_exists($hotName)) {
- $dupeName = rtrim($hotName, ".{$file['extn']}");
- $dupeCount = count(glob($dupeName . '*'));
- $hotName = $dupeName . '_' . ++$dupeCount . '.' . $file['extn'];
- }
- $this->logger->debug(__METHOD__.'|'.__LINE__."|file `{$file['name']}`; clean `{$cleanName}`; hot `{$hotName}`");
- if (!rename($file['tempfile'], $hotName)) {
- $errors[] = "failed to upload `{$file['name']}`";
- $this->logger->error(__METHOD__.'|'.__LINE__."|failed to upload `{$file['name']}`" . error_get_last()['message']);
- @unlink($file['tempfile']);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement