Exemple #1
0
 /**
  * upload file
  *
  * @param string $location where to upload
  * @param string $thename  file name
  * @param string $tempname temp name
  * @param string $tipo     file type
  *
  * @return uploads file
  */
 public static function uploadFile($location, $thename, $tempname, $tipo)
 {
     global $encodeExplorer;
     $extension = File::getFileExtension($thename);
     $filepathinfo = Utils::mbPathinfo($thename);
     $name = Utils::normalizeStr($filepathinfo['filename']) . "." . $extension;
     $upload_dir = $location->getFullPath();
     $upload_file = $upload_dir . $name;
     if (file_exists($upload_file)) {
         Utils::setWarning("<span><i class=\"fa fa-info-circle\"></i> " . $name . " " . $encodeExplorer->getString("file_exists") . "</span> ");
     } else {
         $mime_type = $tipo;
         $clean_file = $upload_dir . FileManager::safeExtension($name, $extension);
         if (!$location->editAllowed() || !$location->isWritable()) {
             Utils::setError("<span><i class=\"fa fa-exclamation-triangle\"></i> " . $encodeExplorer->getString("upload_not_allowed") . "</span> ");
         } elseif (Utils::notList($mime_type, SetUp::getConfig("upload_allow_type")) == true || Utils::inList($extension, SetUp::getConfig("upload_reject_extension")) == true) {
             Utils::setError("<span><i class=\"fa fa-exclamation-triangle\"></i> " . $name . "<strong>." . $extension . "</strong> " . $encodeExplorer->getString("upload_type_not_allowed") . "</span> ");
         } elseif (!is_uploaded_file($tempname)) {
             $encodeExplorer->setErrorString("failed_upload");
         } elseif (!move_uploaded_file($tempname, $clean_file)) {
             $encodeExplorer->setErrorString("failed_move");
         } elseif (Actions::checkUserUp($clean_file) == false) {
             $encodeExplorer->setErrorString("upload_exceeded");
             unlink($clean_file);
         } else {
             chmod($clean_file, 0755);
             //Actions::updateUserSpace($clean_file, true);
             Utils::setSuccess("<span><i class=\"fa fa-check-circle\"></i> " . $name . "</span> ");
             // file successfully uploaded, sending log notification
             Logger::logCreation($location->getDir(true, false, false, 0) . $name, false);
         }
     }
 }