예제 #1
0
 public function addFileInfo(&$file, $filePath, $destDir)
 {
     $params = JUDownloadHelper::getParams();
     if (function_exists('finfo_open')) {
         $finfo = finfo_open(FILEINFO_MIME);
         $file['mime_type'] = finfo_file($finfo, $filePath);
         finfo_close($finfo);
     } elseif (function_exists('mime_content_type')) {
         $file['mime_type'] = mime_content_type($filePath);
     }
     $file['size'] = filesize($filePath);
     if ($params->get('auto_generate_md5_checksum', 2) == 2 && $file['size'] <= $params->get("max_filesize_auto_generate_checksum", 100) * 1024 * 1024 || $params->get('auto_generate_md5_checksum', 2) == 1) {
         $file['md5_checksum'] = hash_file('md5', $filePath);
     } else {
         $file['md5_checksum'] = '';
     }
     if ($params->get('auto_generate_crc32_checksum', 2) == 2 && $file['size'] <= $params->get("max_filesize_auto_generate_checksum", 100) * 1024 * 1024 || $params->get('auto_generate_crc32_checksum', 2) == 1) {
         return $file['crc32_checksum'] = hash_file('crc32b', $filePath);
     } else {
         $file['crc32_checksum'] = '';
     }
     do {
         $file['file_name'] = md5($file['file_name'] . JUDownloadHelper::generateRandomString(10)) . "." . JFile::getExt($file['file_name']);
         $dest = $destDir . $file['doc_id'] . "/" . $file['file_name'];
     } while (JFile::exists($dest));
 }
예제 #2
0
 public function remoteFile()
 {
     $app = JFactory::getApplication();
     if (!$this->isValidUploadURL() || !JUDownloadFrontHelperPermission::canUploadFromUrl($app->input->get('doc_id', null))) {
         $result = array();
         $result['success'] = 0;
         $result['alert'] = JText::_('COM_JUDOWNLOAD_YOU_ARE_NOT_AUTHORIZED_TO_UPLOAD_FILE');
         JUDownloadHelper::obCleanData();
         echo json_encode($result);
         exit;
     }
     $type = $app->input->get('type', '');
     $result = array();
     $file_directory = JPATH_ROOT . "/" . JUDownloadFrontHelper::getDirectory("file_directory", "media/com_judownload/files/");
     $file_directory_tmp = $file_directory . "tmp/";
     if (!JFolder::exists($file_directory_tmp)) {
         JFolder::create($file_directory_tmp);
         $file_index = $file_directory_tmp . 'index.html';
         $buffer = "<!DOCTYPE html><title></title>";
         JFile::write($file_index, $buffer);
     }
     if (!is_writable($file_directory_tmp)) {
         $file_directory_tmp = sys_get_temp_dir() . "/plupload/";
     }
     if ($type === 'loadtransfer') {
         $source_url = $app->input->get('source_url', '', 'string');
         if (!$source_url) {
             $result['success'] = 0;
             $result['alert'] = JText::_('COM_JUDOWNLOAD_SOURCE_URL_IS_MISSING');
         }
         $file = $this->loadTransfer($source_url);
         if ($file) {
             $file_name = end(explode("/", $source_url));
             $file_extension = end(explode(".", $file_name));
             do {
                 $target_name = md5(JUDownloadHelper::generateRandomString(10)) . "." . $file_extension;
             } while (JFile::exists($file_directory_tmp . $target_name));
             $result['success'] = 1;
             $result['size'] = (int) $file[1];
             $result['type'] = (string) $file[2];
             $result['name'] = $file_name;
             $result['target_name'] = $target_name;
         } else {
             $result['success'] = 0;
             $result['alert'] = JText::_('COM_JUDOWNLOAD_INVALID_FILE');
         }
     } elseif ($type === 'transferfile') {
         $target_name = $app->input->get('target_name', '', 'string');
         $source_url = $app->input->get('source_url', '', 'string');
         if (!$source_url) {
             $result['success'] = 0;
             $result['alert'] = JText::_('COM_JUDOWNLOAD_INVALID_SOURCE_URL');
         } elseif (!$target_name) {
             $result['success'] = 0;
             $result['alert'] = JText::_('COM_JUDOWNLOAD_INVALID_TARGET_NAME');
         } elseif ($this->remoteDownload($source_url, $file_directory_tmp . $target_name, 1024)) {
             $result['success'] = 1;
             $result['alert'] = JText::_('COM_JUDOWNLOAD_DOWNLOAD_REMOTE_FILE_SUCCESSFULLY');
         } else {
             $result['success'] = 0;
             $result['alert'] = JText::_('COM_JUDOWNLOAD_FAIL_TO_DOWNLOAD_REMOTE_FILE');
         }
     } elseif ($type === 'getprocess') {
         $target_name = $app->input->get('target_name', '', 'string');
         $file_size = $app->input->getInt('file_size', 0);
         $current_size = filesize($file_directory_tmp . $target_name);
         if ($current_size === false || !$file_size) {
             $result['success'] = 0;
             $result['alert'] = JText::_('COM_JUDOWNLOAD_FAIL_TO_GET_FILE_TRANSFER_STATUS');
         } else {
             if ($current_size >= $file_size) {
                 $percent = 100;
             } else {
                 $percent = round($current_size / $file_size * 100);
             }
             $result['success'] = 1;
             $result['alert'] = '';
             $result['percent'] = $percent;
         }
     }
     if ($type === 'cancel') {
         $target_name = $app->input->get('target_name', '', 'string');
         if (JFile::exists($file_directory_tmp . $target_name)) {
             JFile::delete($file_directory_tmp . $target_name);
         }
     }
     JUDownloadHelper::obCleanData();
     echo json_encode($result);
     exit;
 }
예제 #3
0
 public static function generateImageNameByDocument($doc_id, $file_name)
 {
     if (!$doc_id || !$file_name) {
         return "";
     }
     $dir_document_ori = JPATH_ROOT . "/" . JUDownloadFrontHelper::getDirectory("document_original_image_directory", "media/com_judownload/images/gallery/original/") . $doc_id . "/";
     $info = pathinfo($file_name);
     $document = JUDownloadHelper::getDocumentById($doc_id);
     $replace = array('id' => $document->id, 'category' => '', 'document' => $document->title, 'image_name' => $info['filename']);
     $base_file_name = JUDownloadHelper::parseImageNameByTags($replace, 'document', null, $document->id) . "." . $info['extension'];
     $img_file_name = $base_file_name;
     $img_path_ori = $dir_document_ori . $img_file_name;
     while (JFile::exists($img_path_ori)) {
         $img_file_name = JUDownloadHelper::generateRandomString(3) . "-" . $base_file_name;
         $img_path_ori = $dir_document_ori . $img_file_name;
     }
     return $img_file_name;
 }