Beispiel #1
0
 public static function uploadFileAndGetPath($FILES, $fieldName, $delete_old, $type = AdminFunctions::VALIDATE_TYPES_ADOBE, $returnFullPath = false, &$size = null)
 {
     if ($FILES[$fieldName]['size'] > 0) {
         //get type
         $mimeType = $FILES[$fieldName]['type'];
         //explode name string to get extension
         $extensionArr = explode(".", $_FILES[$fieldName]['name']);
         //get temp name
         $tmp_name = $FILES[$fieldName]['tmp_name'];
         //if type is valid
         if (AdminFunctions::IsValidFileType($mimeType, $type)) {
             //empty extension by default
             $extension = '';
             //get extension from exploded string-array if possible
             if (count($extensionArr) > 1) {
                 $extension = $extensionArr[count($extensionArr) - 1];
             }
             //make random file name and add extension to it
             $randomFileName = AdminFunctions::generateString(15) . "." . $extension;
             //make new file path
             $newFilePath = Constants::UPLOAD_FILE_DIR . $randomFileName;
             //try to copy
             if (copy($tmp_name, $newFilePath)) {
                 if ($size != null) {
                     $size = $FILES[$fieldName]['size'];
                 }
                 DwHelper::deleteFile($delete_old);
                 if ($returnFullPath) {
                     return $newFilePath;
                 } else {
                     return $randomFileName;
                 }
             } else {
                 return "";
             }
         } else {
             return "";
         }
     } else {
         return "";
     }
 }