Example #1
0
 public static function getFileToUpload(&$params)
 {
     $result = "";
     $path = JPATH_SITE . DIRECTORY_SEPARATOR . $params->get('efu_parent') . DIRECTORY_SEPARATOR . $params->get('efu_folder');
     if ($params->get('efu_user') == true) {
         //get the user data
         $user =& JFactory::getUser();
         if ($user->guest == false) {
             $path .= DIRECTORY_SEPARATOR . $user->username;
         } else {
             //If it is a guest user, then store the file in the 'efu_folder'.
             //You can add something here, if you have a special folder that
             //you want to add the guest uploads to.
             //$path.= DIRECTORY_SEPARATOR.'your_guest_folder';
         }
     }
     //check to see if the upload process has started
     if (isset($_FILES[$params->get('efu_variable')])) {
         //now, we're going to check each of the uploaded files
         $total = intval($params->get('efu_multiple'));
         for ($i = 0; $i < $total; $i++) {
             //so, now, check for any other errors
             if ($_FILES[$params->get('efu_variable')]["error"][$i] > 0) {
                 //error was found. Show the return code.
                 $result .= JText::_('MOD_EFU_RETURN_CODE') . ": " . $_FILES[$params->get('efu_variable')]["error"][$i] . "<br />";
                 $result .= modEasyFileUploaderHelper::fileUploadErrorMessage($_FILES[$params->get('efu_variable')]["error"][$i]);
             } else {
                 //no errors found.
                 //check to see if the file type is correct
                 //but first, we have to store the file types in a variable. I was getting an issue with empty()
                 if (modEasyFileUploaderHelper::isValidFileType($params, $i)) {
                     //the file type is permitted
                     //so, check for the right size
                     if ($_FILES[$params->get('efu_variable')]["size"][$i] < $params->get('efu_maxsize')) {
                         //file is an acceptable size
                         //check to see if file already exists in the destination folder
                         if (file_exists($path . DIRECTORY_SEPARATOR . $_FILES[$params->get('efu_variable')]["name"][$i])) {
                             //file already exists
                             //check whether the user wants to replace the file or not.
                             if ($params->get('efu_replace') == true && $_POST["answer"] == true) {
                                 //yep, the user wants to replace the file, so just delete the existing file
                                 JFile::delete($path . DIRECTORY_SEPARATOR . $_FILES[$params->get('efu_variable')]["name"][$i]);
                                 $result .= JText::_('MOD_EFU_REPLACEMENT_APPROVED') . " ";
                                 modEasyFileUploaderHelper::storeUploadedFile($path, $params, $result, $i);
                             } else {
                                 $result .= $_FILES[$params->get('efu_variable')]["name"][$i] . " " . JText::_('MOD_EFU_ALREADY_EXISTS');
                             }
                         } else {
                             modEasyFileUploaderHelper::storeUploadedFile($path, $params, $result, $i);
                         }
                     } else {
                         //file is too large
                         $result .= JText::_('MOD_EFU_TOO_LARGE_ERROR') . modEasyFileUploaderHelper::sizeToText($params->get('efu_maxsize')) . ".";
                     }
                 } else {
                     //the file type is not permitted
                     $fakeMIME = $_FILES[$params->get('efu_variable')]["type"][$i];
                     $trueMIME = modEasyFileUploaderHelper::actualMIME($_FILES[$params->get('efu_variable')]["tmp_name"][$i]);
                     $result .= JText::_('MOD_EFU_INVALID_ERROR') . "<br />" . JText::_('MOD_EFU_PHP_MIME_ERROR') . ($trueMIME !== false ? "(" . $trueMIME . ")" : "") . "<br />" . JText::_('MOD_EFU_BROWSER_MIME_ERROR') . $fakeMIME;
                 }
             }
             if ($i < $total - 1) {
                 $result .= "<hr />";
             }
         }
     }
     return $result;
 }