<?php echo JHtml::_('tabs.start', 'judownload-files', array('useCookie' => 1)); ?> <?php echo JHtml::_('tabs.panel', JText::_('COM_JUDOWNLOAD_UPLOADER_TAB'), 'file-uploader'); ?> <div id="judl-uploader" style="margin: 10px;"> <p><?php echo JText::_("COM_JUDOWNLOAD_YOUR_BROWSER_DOESNT_HAVE_FLASH_SILVERLIGHT_OR_HTML5_SUPPORT"); ?> </p> </div> <?php if (JUDownloadFrontHelperPermission::canUploadFromUrl($this->item->id)) { echo JHtml::_('tabs.panel', JText::_('COM_JUDOWNLOAD_FIELD_REMOTE_UPLOAD'), 'remote-file'); ?> <div id="remote-file" class="remote-file"> <div class="progress progress-striped"> <div class="bar" style="width: 0%;"></div> </div> <div class="clearfix"> <input type="text" class="source-url input-xlarge" size="78" value="" placeholder="<?php echo JText::_("COM_JUDOWNLOAD_FILE_URL"); ?> " /> <input class="btn btn-primary process-remote-file" type="button" value="<?php echo JText::_("COM_JUDOWNLOAD_TRANSFER_FILE"); ?> " />
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; }