本文整理汇总了PHP中DocumentManager::file_send_for_download方法的典型用法代码示例。如果您正苦于以下问题:PHP DocumentManager::file_send_for_download方法的具体用法?PHP DocumentManager::file_send_for_download怎么用?PHP DocumentManager::file_send_for_download使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DocumentManager
的用法示例。
在下文中一共展示了DocumentManager::file_send_for_download方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: export_complex_table_xml
/**
* Export hierarchical tabular data to XML-file
* @param array Hierarchical array of data to put in XML, each element presenting a 'name' and a 'value' property
* @param string Name of file to be given to the user
* @param string Name of common tag to place each line in
* @param string Name of the root element. A root element should always be given.
* @param string Encoding in which the data is provided
* @return void Prompts the user for a file download
*/
public static function export_complex_table_xml($data, $filename = 'export', $wrapper_tagname, $encoding = 'ISO-8859-1')
{
$file = api_get_path(SYS_ARCHIVE_PATH) . '/' . uniqid('') . '.xml';
$handle = fopen($file, 'a+');
fwrite($handle, '<?xml version="1.0" encoding="' . $encoding . '"?>' . "\n");
if (!is_null($wrapper_tagname)) {
fwrite($handle, '<' . $wrapper_tagname . '>');
}
$s = self::_export_complex_table_xml_helper($data);
fwrite($handle, $s);
if (!is_null($wrapper_tagname)) {
fwrite($handle, '</' . $wrapper_tagname . '>' . "\n");
}
fclose($handle);
DocumentManager::file_send_for_download($file, true, $filename . '.xml');
return false;
}
示例2: trim
if ($not_deleted_file['contains_file'] == 0) {
$filename = trim($filename) . ".html";
$work_temp = api_get_path(SYS_ARCHIVE_PATH) . api_get_unique_id() . '_' . $filename;
file_put_contents($work_temp, $not_deleted_file['description']);
$files[basename($work_temp)] = $filename;
$zip_folder->add($work_temp, PCLZIP_OPT_REMOVE_PATH, api_get_path(SYS_ARCHIVE_PATH), PCLZIP_CB_PRE_ADD, 'my_pre_add_callback');
@unlink($work_temp);
}
}
if (!empty($files)) {
//logging
event_download(basename($work_data['title']) . '.zip (folder)');
//start download of created file
$name = basename($work_data['title']) . '.zip';
if (Security::check_abs_path($temp_zip_file, api_get_path(SYS_ARCHIVE_PATH))) {
DocumentManager::file_send_for_download($temp_zip_file, true, $name);
@unlink($temp_zip_file);
exit;
}
} else {
exit;
}
/* Extra function (only used here) */
function my_pre_add_callback($p_event, &$p_header)
{
global $files;
if (isset($files[basename($p_header['stored_filename'])])) {
$p_header['stored_filename'] = $files[basename($p_header['stored_filename'])];
return 1;
}
return 0;
示例3: htmlToOdt
/**
* Export HTML content in a ODF document
* @param string $html
* @param string $name
* @param string $format
*
* @return bool
*/
public static function htmlToOdt($html, $name, $format = 'odt')
{
$unoconv = api_get_configuration_value('unoconv.binaries');
if (empty($unoconv)) {
return false;
}
if (!empty($html)) {
$fs = new Filesystem();
$paths = ['root_sys' => api_get_path(SYS_PATH), 'path.temp' => api_get_path(SYS_ARCHIVE_PATH)];
$connector = new Connector();
$drivers = new DriversContainer();
$drivers['configuration'] = array('unoconv.binaries' => $unoconv, 'unoconv.timeout' => 60);
$tempFilesystem = TemporaryFilesystem::create();
$manager = new Manager($tempFilesystem, $fs);
$alchemyst = new Alchemyst($drivers, $manager);
$dataFileSystem = new Data($paths, $fs, $connector, $alchemyst);
$content = $dataFileSystem->convertRelativeToAbsoluteUrl($html);
$filePath = $dataFileSystem->putContentInTempFile($content, api_replace_dangerous_char($name), 'html');
$try = true;
while ($try) {
try {
$convertedFile = $dataFileSystem->transcode($filePath, $format);
$try = false;
DocumentManager::file_send_for_download($convertedFile, false, $name . '.' . $format);
} catch (Exception $e) {
// error_log($e->getMessage());
}
}
}
}
示例4: scorm_export
//.........这里部分代码省略.........
}
//error_log(__LINE__.'checking existence of '.$main_path.$file_path.'',0);
if (!is_file($main_path . $file_path) || !is_readable($main_path . $file_path)) {
continue;
}
//error_log(__LINE__.'getting document from '.$main_path.$file_path.' removing '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/',0);
$dest_file = $archive_path . $temp_dir_short . '/document/' . $file_path;
$this->create_path($dest_file);
//error_log('Created path '.api_get_path(SYS_ARCHIVE_PATH).$temp_dir_short.'/document/'.$file_path,0);
//error_log('copy '.api_get_path(SYS_COURSE_PATH).$_course['path'].'/'.$file_path.' to '.api_get_path(SYS_ARCHIVE_PATH).$temp_dir_short.'/'.$file_path,0);
//echo $main_path.$file_path.' - '.$dest_file.'<br>';
copy($main_path . $file_path, $dest_file);
//check if the file needs a link update
if (in_array($file_path, array_keys($link_updates))) {
$string = file_get_contents($dest_file);
unlink($dest_file);
foreach ($link_updates[$file_path] as $old_new) {
//error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path,0);
//this is an ugly hack that allows .flv files to be found by the flv player that
// will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
// to find the flv to play in document/main/, so we replace main/ in the flv path by
// ../../.. to return from inc/lib/flv_player to the document/main path
if (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 5) == 'main/') {
$old_new['dest'] = str_replace('main/', '../../../', $old_new['dest']);
}
if (substr($old_new['dest'], 0, 1) == '/') {
$old_new['dest'] = substr($old_new['dest'], 1);
}
$string = str_replace($old_new['orig'], $old_new['dest'], $string);
$string = str_replace(str_replace('https', 'http', $old_new['orig']), $old_new['dest'], $string);
}
file_put_contents($dest_file, $string);
}
}
if (is_array($links_to_create)) {
foreach ($links_to_create as $file => $link) {
$file_content = '<html><body><div style="text-align:center"><a href="' . $link['url'] . '">' . $link['title'] . '</a></div></body></html>';
file_put_contents($archive_path . $temp_dir_short . '/' . $file, $file_content);
}
}
// add non exportable message explanation
$lang_not_exportable = get_lang('ThisItemIsNotExportable');
$file_content = <<<EOD
<html>
\t<head>
\t\t<style>
\t\t\t.error-message {
\t\t\t\tfont-family: arial, verdana, helvetica, sans-serif;
\t\t\t\tborder-width: 1px;
\t\t\t\tborder-style: solid;
\t\t\t\tleft: 50%;
\t\t\t\tmargin: 10px auto;
\t\t\t\tmin-height: 30px;
\t\t\t\tpadding: 5px;
\t\t\t\tright: 50%;
\t\t\t\twidth: 500px;
\t\t\t\tbackground-color: #FFD1D1;
\t\t\t\tborder-color: #FF0000;
\t\t\t\tcolor: #000;
\t\t\t}
\t\t</style>
\t<body>
\t\t<div class="error-message">
\t\t\t{$lang_not_exportable}
\t\t</div>
\t</body>
</html>
EOD;
if (!is_dir($archive_path . $temp_dir_short . '/document')) {
@mkdir($archive_path . $temp_dir_short . '/document');
}
file_put_contents($archive_path . $temp_dir_short . '/document/non_exportable.html', $file_content);
//Add the extra files that go along with a SCORM package
$main_code_path = api_get_path(SYS_CODE_PATH) . 'newscorm/packaging/';
$extra_files = scandir($main_code_path);
foreach ($extra_files as $extra_file) {
if (strpos($extra_file, '.') === 0) {
continue;
} else {
$dest_file = $archive_path . $temp_dir_short . '/' . $extra_file;
$this->create_path($dest_file);
copy($main_code_path . $extra_file, $dest_file);
}
}
//Finalize the imsmanifest structure, add to the zip, then return the zip
$xmldoc->save($archive_path . '/' . $temp_dir_short . '/imsmanifest.xml');
$zip_folder->add($archive_path . '/' . $temp_dir_short, PCLZIP_OPT_REMOVE_PATH, $archive_path . '/' . $temp_dir_short . '/');
//clean possible temporary files
foreach ($files_cleanup as $file) {
$res = unlink($file);
if ($res === false) {
error_log('Could not delete temp file ' . $file . ' ' . __FILE__ . ' ' . __LINE__, 0);
}
}
//Send file to client
//$name = 'scorm_export_'.$this->lp_id.'.zip';
require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php';
$name = preg_replace('([^a-zA-Z0-9_\\.])', '-', html_entity_decode($this->get_name(), ENT_QUOTES)) . '.zip';
DocumentManager::file_send_for_download($temp_zip_file, true, $name);
}
示例5: api_protect_course_script
* but this code will hopefully be replaced soon by an Apache URL
* rewrite mechanism.
*
* @package chamilo.work
*/
//require_once '../inc/global.inc.php';
require_once 'work.lib.php';
// Course protection
api_protect_course_script(true);
$commentId = isset($_GET['comment_id']) ? intval($_GET['comment_id']) : null;
if (empty($commentId)) {
api_not_allowed(true);
}
$workData = getWorkComment($commentId);
$courseInfo = api_get_course_info();
if (!empty($workData)) {
if (empty($workData['file_path']) || isset($workData['file_path']) && !file_exists($workData['file_path'])) {
api_not_allowed(true);
}
$work = get_work_data_by_id($workData['work_id']);
protectWork($courseInfo, $work['parent_id']);
if (user_is_author($workData['work_id']) || $courseInfo['show_score'] == 0 && $work['active'] == 1 && $work['accepted'] == 1) {
if (Security::check_abs_path($workData['file_path'], api_get_path(SYS_COURSE_PATH) . api_get_course_path() . '/')) {
DocumentManager::file_send_for_download($workData['file_path'], true, $workData['file_name_to_show']);
}
} else {
api_not_allowed(true);
}
} else {
api_not_allowed(true);
}
示例6: export_zip
/**
* Exports the current SCORM object's files as a zip. Excerpts taken from learnpath_functions.inc.php::exportpath()
* @param integer Learnpath ID (optional, taken from object context if not defined)
*/
function export_zip($lp_id = null)
{
if ($this->debug > 0) {
error_log('In scorm::export_zip method(' . $lp_id . ')', 0);
}
if (empty($lp_id)) {
if (!is_object($this)) {
return false;
} else {
$id = $this->get_id();
if (empty($id)) {
return false;
} else {
$lp_id = $this->get_id();
}
}
}
//error_log('New LP - in export_zip()',0);
//zip everything that is in the corresponding scorm dir
//write the zip file somewhere (might be too big to return)
require_once 'learnpath_functions.inc.php';
$course_id = api_get_course_int_id();
$tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
$_course = api_get_course_info(api_get_course_id());
$sql = "SELECT * FROM {$tbl_lp} WHERE c_id = " . $course_id . " AND id=" . $lp_id;
$result = Database::query($sql);
$row = Database::fetch_array($result);
$LPname = $row['path'];
$list = split('/', $LPname);
$LPnamesafe = $list[0];
//$zipfoldername = '/tmp';
//$zipfoldername = '../../courses/'.$_course['directory'].'/temp/'.$LPnamesafe;
$zipfoldername = api_get_path(SYS_COURSE_PATH) . $_course['directory'] . '/temp/' . $LPnamesafe;
$scormfoldername = api_get_path(SYS_COURSE_PATH) . $_course['directory'] . '/scorm/' . $LPnamesafe;
$zipfilename = $zipfoldername . '/' . $LPnamesafe . '.zip';
// Get a temporary dir for creating the zip file.
//error_log('New LP - cleaning dir '.$zipfoldername, 0);
deldir($zipfoldername);
// Make sure the temp dir is cleared.
$res = mkdir($zipfoldername, api_get_permissions_for_new_directories());
//error_log('New LP - made dir '.$zipfoldername, 0);
// Create zipfile of given directory.
$zip_folder = new PclZip($zipfilename);
$zip_folder->create($scormfoldername . '/', PCLZIP_OPT_REMOVE_PATH, $scormfoldername . '/');
//$zipfilename = '/var/www/chamilo/courses/TEST2/scorm/example_document.html';
//This file sending implies removing the default mime-type from php.ini
//DocumentManager :: file_send_for_download($zipfilename, true, $LPnamesafe.'.zip');
DocumentManager::file_send_for_download($zipfilename, true);
// Delete the temporary zip file and directory in fileManager.lib.php
FileManager::my_delete($zipfilename);
FileManager::my_delete($zipfoldername);
return true;
}
示例7: export_zip
/**
* Exports the current AICC object's files as a zip. Excerpts taken from learnpath_functions.inc.php::exportpath()
* @param integer Learnpath ID (optional, taken from object context if not defined)
*/
function export_zip($lp_id = null)
{
if ($this->debug > 0) {
error_log('In aicc::export_zip method(' . $lp_id . ')', 0);
}
if (empty($lp_id)) {
if (!is_object($this)) {
return false;
} else {
$id = $this->get_id();
if (empty($id)) {
return false;
} else {
$lp_id = $this->get_id();
}
}
}
//error_log('New LP - in export_zip()',0);
//zip everything that is in the corresponding scorm dir
//write the zip file somewhere (might be too big to return)
require_once api_get_path(LIBRARY_PATH) . "fileUpload.lib.php";
require_once api_get_path(LIBRARY_PATH) . "fileManage.lib.php";
require_once api_get_path(LIBRARY_PATH) . "document.lib.php";
require_once api_get_path(LIBRARY_PATH) . "pclzip/pclzip.lib.php";
require_once "learnpath_functions.inc.php";
$tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
$_course = Database::get_course_info(api_get_course_id());
$sql = "SELECT * FROM {$tbl_lp} WHERE id=" . $lp_id;
$result = Database::query($sql, __FILE__, __LINE__);
$row = Database::fetch_array($result);
$LPname = $row['path'];
$list = split('/', $LPname);
$LPnamesafe = $list[0];
//$zipfoldername = '/tmp';
//$zipfoldername = '../../courses/'.$_course['directory']."/temp/".$LPnamesafe;
$zipfoldername = api_get_path('SYS_COURSE_PATH') . $_course['directory'] . "/temp/" . $LPnamesafe;
$scormfoldername = api_get_path('SYS_COURSE_PATH') . $_course['directory'] . "/scorm/" . $LPnamesafe;
$zipfilename = $zipfoldername . "/" . $LPnamesafe . ".zip";
//Get a temporary dir for creating the zip file
//error_log('New LP - cleaning dir '.$zipfoldername,0);
deldir($zipfoldername);
//make sure the temp dir is cleared
$res = mkdir($zipfoldername);
//error_log('New LP - made dir '.$zipfoldername,0);
//create zipfile of given directory
$zip_folder = new PclZip($zipfilename);
$zip_folder->create($scormfoldername . '/', PCLZIP_OPT_REMOVE_PATH, $scormfoldername . '/');
//$zipfilename = '/var/www/dokeos-comp/courses/TEST2/scorm/example_document.html';
//this file sending implies removing the default mime-type from php.ini
//DocumentManager :: file_send_for_download($zipfilename, true, $LPnamesafe.".zip");
DocumentManager::file_send_for_download($zipfilename, true);
// Delete the temporary zip file and directory in fileManage.lib.php
my_delete($zipfilename);
my_delete($zipfoldername);
return true;
}
示例8: array
$language_file = array('courses', 'index', 'admin');
$user_id = api_get_user_id();
if (!isset($_GET['file']) || !isset($_GET['title']) || !isset($_GET['ticket_id'])) {
api_not_allowed();
}
if (!api_is_platform_admin()) {
$ticket_id = $_GET['ticket_id'];
$table_support_messages = Database::get_main_table(TABLE_SUPPORT_MESSAGE);
$table_support_tickets = Database::get_main_table(TABLE_SUPPORT_TICKET);
$table_support_message_attachments = Database::get_main_table(TABLE_SUPPORT_MESSAGE_ATTACHMENTS);
$sql = "SELECT DISTINCT ticket.request_user FROM {$table_support_tickets} ticket, {$table_support_messages} message, {$table_support_message_attachments} attch \n\t\t\tWHERE ticket.ticket_id = message.ticket_id AND attch.message_id = message.message_id AND ticket.ticket_id = {$ticket_id}";
$rs = Database::query($sql);
$row_users = Database::fetch_array($rs, 'ASSOC');
$user_request_id = $row_users['request_user'];
if (intval($user_request_id) != $user_id) {
api_not_allowed();
}
}
$file_url = $_GET['file'];
$file_url = str_replace('///', '&', $file_url);
$file_url = str_replace(' ', '+', $file_url);
$file_url = str_replace('/..', '', $file_url);
$file_url = Database::escape_string($file_url);
$title = $_GET['title'];
$path_attachment = api_get_path(SYS_PATH);
$path_message_attach = $path_attachment . 'tck_messageattch/';
$full_file_name = $path_message_attach . $file_url;
if (Security::check_abs_path($full_file_name, $path_message_attach)) {
DocumentManager::file_send_for_download($full_file_name, TRUE, $title);
}
exit;
示例9: export_complete_report_xls
//.........这里部分代码省略.........
// Database table definitions
$table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION);
$table_survey_question_option = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION);
$table_survey_answer = Database::get_course_table(TABLE_SURVEY_ANSWER);
$course_id = api_get_course_int_id();
// First line (questions)
$sql = "SELECT\n questions.question_id,\n questions.type,\n questions.survey_question,\n count(options.question_option_id) as number_of_options\n\t\t\t\tFROM {$table_survey_question} questions\n\t\t\t\tLEFT JOIN {$table_survey_question_option} options\n ON questions.question_id = options.question_id AND options.c_id = {$course_id}\n\t\t\t\tWHERE\n\t\t\t\t questions.survey_id = '" . intval($_GET['survey_id']) . "' AND\n\t\t\t\t questions.c_id = {$course_id}\n\t\t\t\tGROUP BY questions.question_id\n\t\t\t\tORDER BY questions.sort ASC";
$result = Database::query($sql);
while ($row = Database::fetch_array($result)) {
// We show the questions if
// 1. there is no question filter and the export button has not been clicked
// 2. there is a quesiton filter but the question is selected for display
if (!$_POST['submit_question_filter'] || is_array($_POST['questions_filter']) && in_array($row['question_id'], $_POST['questions_filter'])) {
// We do not show comment and pagebreak question types
if ($row['type'] != 'comment' && $row['type'] != 'pagebreak') {
if ($row['number_of_options'] == 0 && $row['type'] == 'open') {
$worksheet->SetCellValueByColumnAndRow($line, $column, api_html_entity_decode(strip_tags($row['survey_question']), ENT_QUOTES));
$column++;
} else {
for ($ii = 0; $ii < $row['number_of_options']; $ii++) {
$worksheet->SetCellValueByColumnAndRow($line, $column, api_html_entity_decode(strip_tags($row['survey_question']), ENT_QUOTES));
$column++;
}
}
}
}
}
$line++;
$column = 1;
// Show extra field values
if ($display_extra_user_fields) {
// Show the fields names for user fields
foreach ($extra_user_fields as &$field) {
$worksheet->SetCellValueByColumnAndRow($line, $column, api_html_entity_decode(strip_tags($field[3]), ENT_QUOTES));
$column++;
}
}
// Getting all the questions and options (second line)
$sql = "SELECT\n survey_question.question_id, survey_question.survey_id, survey_question.survey_question, survey_question.display, survey_question.sort, survey_question.type,\n survey_question_option.question_option_id, survey_question_option.option_text, survey_question_option.sort as option_sort\n\t\t\t\tFROM {$table_survey_question} survey_question\n\t\t\t\tLEFT JOIN {$table_survey_question_option} survey_question_option\n\t\t\t\tON survey_question.question_id = survey_question_option.question_id AND survey_question_option.c_id = {$course_id}\n\t\t\t\tWHERE survey_question.survey_id = '" . intval($_GET['survey_id']) . "' AND\n\t\t\t\tsurvey_question.c_id = {$course_id}\n\t\t\t\tORDER BY survey_question.sort ASC, survey_question_option.sort ASC";
$result = Database::query($sql);
$possible_answers = array();
$possible_answers_type = array();
while ($row = Database::fetch_array($result)) {
// We show the options if
// 1. there is no question filter and the export button has not been clicked
// 2. there is a quesiton filter but the question is selected for display
if (!$_POST['submit_question_filter'] || is_array($_POST['questions_filter']) && in_array($row['question_id'], $_POST['questions_filter'])) {
// We do not show comment and pagebreak question types
if ($row['type'] != 'comment' && $row['type'] != 'pagebreak') {
$worksheet->SetCellValueByColumnAndRow($line, $column, api_html_entity_decode(strip_tags($row['option_text']), ENT_QUOTES));
$possible_answers[$row['question_id']][$row['question_option_id']] = $row['question_option_id'];
$possible_answers_type[$row['question_id']] = $row['type'];
$column++;
}
}
}
// Getting all the answers of the users
$line++;
$column = 0;
$old_user = '';
$answers_of_user = array();
$sql = "SELECT * FROM {$table_survey_answer}\n WHERE c_id = {$course_id} AND survey_id='" . intval($_GET['survey_id']) . "' ";
if ($user_id != 0) {
$sql .= "AND user='" . intval($user_id) . "' ";
}
$sql .= "ORDER BY user ASC";
$open_question_iterator = 1;
$result = Database::query($sql);
while ($row = Database::fetch_array($result)) {
if ($old_user != $row['user'] && $old_user != '') {
$return = SurveyUtil::export_complete_report_row_xls($survey_data, $possible_answers, $answers_of_user, $old_user, true);
foreach ($return as $elem) {
$worksheet->SetCellValueByColumnAndRow($line, $column, $elem);
$column++;
}
$answers_of_user = array();
$line++;
$column = 0;
}
if ($possible_answers_type[$row['question_id']] == 'open') {
$temp_id = 'open' . $open_question_iterator;
$answers_of_user[$row['question_id']][$temp_id] = $row;
$open_question_iterator++;
} else {
$answers_of_user[$row['question_id']][$row['option_id']] = $row;
}
$old_user = $row['user'];
}
$return = SurveyUtil::export_complete_report_row_xls($survey_data, $possible_answers, $answers_of_user, $old_user, true);
// this is to display the last user
foreach ($return as $elem) {
$worksheet->SetCellValueByColumnAndRow($line, $column, $elem);
$column++;
}
$file = api_get_path(SYS_ARCHIVE_PATH) . api_replace_dangerous_char($filename);
$writer = new PHPExcel_Writer_Excel2007($spreadsheet);
$writer->save($file);
DocumentManager::file_send_for_download($file, true, $filename);
return null;
}
示例10: export_csv
public function export_csv()
{
$course = Request::get_course_key();
$items = Notebook::repository()->find_by_course($course);
$writer = CsvWriter::create();
$writer->add($items);
$path = $writer->get_path();
\DocumentManager::file_send_for_download($path, true, get_lang('Notebook') . '.csv');
}
示例11: zip_download
/**
* This function downloads all the files of the input array into one zip
* @param array $fileList containing all the ids of the files that have to be downloaded.
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @todo consider removing the check if the user has received or sent this file (zip download of a folder already sufficiently checks for this).
* @todo integrate some cleanup function that removes zip files that are older than 2 days
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @author Julio Montoya Addin c_id support
* @version march 2006
*/
function zip_download($fileList)
{
$_course = api_get_course_info();
$dropbox_cnf = getDropboxConf();
$course_id = api_get_course_int_id();
$fileList = array_map('intval', $fileList);
// note: we also have to add the check if the user has received or sent this file.
$sql = "SELECT DISTINCT file.filename, file.title, file.author, file.description\n FROM " . $dropbox_cnf['tbl_file'] . " file\n INNER JOIN " . $dropbox_cnf['tbl_person'] . " person\n ON (person.file_id=file.id AND file.c_id = {$course_id} AND person.c_id = {$course_id})\n INNER JOIN " . $dropbox_cnf['tbl_post'] . " post\n ON (post.file_id = file.id AND post.c_id = {$course_id} AND file.c_id = {$course_id})\n WHERE\n file.id IN (" . implode(', ', $fileList) . ") AND\n file.id = person.file_id AND\n (\n person.user_id = '" . api_get_user_id() . "' OR\n post.dest_user_id = '" . api_get_user_id() . "'\n ) ";
$result = Database::query($sql);
$files = array();
while ($row = Database::fetch_array($result)) {
$files[$row['filename']] = array('filename' => $row['filename'], 'title' => $row['title'], 'author' => $row['author'], 'description' => $row['description']);
}
// Step 3: create the zip file and add all the files to it
$temp_zip_file = api_get_path(SYS_ARCHIVE_PATH) . api_get_unique_id() . ".zip";
Session::write('dropbox_files_to_download', $files);
$zip = new PclZip($temp_zip_file);
foreach ($files as $value) {
$zip->add(api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/dropbox/' . $value['filename'], PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_CB_PRE_ADD, 'my_pre_add_callback');
}
Session::erase('dropbox_files_to_download');
$name = 'dropbox-' . api_get_utc_datetime() . '.zip';
DocumentManager::file_send_for_download($temp_zip_file, true, $name);
@unlink($temp_zip_file);
exit;
}
示例12: api_get_path
<?php
/* For licensing terms, see /license.txt */
/**
* Download script for course info
* @package chamilo.course_info
*/
////require_once '../inc/global.inc.php';
$this_section = SECTION_COURSES;
$_cid = false;
if (isset($_GET['session']) && $_GET['session']) {
$archive_path = api_get_path(SYS_ARCHIVE_PATH) . 'temp/';
$_cid = true;
$is_courseAdmin = true;
} else {
$archive_path = api_get_path(SYS_ARCHIVE_PATH);
}
$archive_file = isset($_GET['archive']) ? $_GET['archive'] : null;
$archive_file = str_replace(array('..', '/', '\\'), '', $archive_file);
list($extension) = getextension($archive_file);
if (empty($extension) || !file_exists($archive_path . $archive_file)) {
api_not_allowed(true);
}
if (Security::check_abs_path($archive_path . $archive_file, $archive_path)) {
DocumentManager::file_send_for_download($archive_path . $archive_file, true, $archive_file);
exit;
} else {
api_not_allowed(true);
}
示例13: scorm_export
//.........这里部分代码省略.........
continue;
}
$dest_file = $archive_path . $temp_dir_short . '/document/' . $file_path;
$this->create_path($dest_file);
copy($main_path . $file_path, $dest_file);
// Check if the file needs a link update.
if (in_array($file_path, array_keys($link_updates))) {
$string = file_get_contents($dest_file);
unlink($dest_file);
foreach ($link_updates[$file_path] as $old_new) {
// This is an ugly hack that allows .flv files to be found by the flv player that
// will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
// to find the flv to play in document/main/, so we replace main/ in the flv path by
// ../../.. to return from inc/lib/flv_player to the document/main path.
if (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 5) == 'main/') {
$old_new['dest'] = str_replace('main/', '../../../', $old_new['dest']);
}
$string = str_replace($old_new['orig'], $old_new['dest'], $string);
}
file_put_contents($dest_file, $string);
}
}
if (is_array($links_to_create)) {
foreach ($links_to_create as $file => $link) {
$file_content = '<!DOCTYPE html><head>
<meta charset="' . api_get_language_isocode() . '" />
<title>' . $link['title'] . '</title>
</head>
<body dir="' . api_get_text_direction() . '">
<div style="text-align:center">
<a href="' . $link['url'] . '">' . $link['title'] . '</a></div>
</body>
</html>';
file_put_contents($archive_path . $temp_dir_short . '/' . $file, $file_content);
}
}
// Add non exportable message explanation.
$lang_not_exportable = get_lang('ThisItemIsNotExportable');
$file_content = '<!DOCTYPE html><head>
<meta charset="' . api_get_language_isocode() . '" />
<title>' . $lang_not_exportable . '</title>
<meta http-equiv="Content-Type" content="text/html; charset=' . api_get_system_encoding() . '" />
</head>
<body dir="' . api_get_text_direction() . '">';
$file_content .= <<<EOD
<style>
.error-message {
font-family: arial, verdana, helvetica, sans-serif;
border-width: 1px;
border-style: solid;
left: 50%;
margin: 10px auto;
min-height: 30px;
padding: 5px;
right: 50%;
width: 500px;
background-color: #FFD1D1;
border-color: #FF0000;
color: #000;
}
</style>
<body>
<div class="error-message">
{$lang_not_exportable}
</div>
</body>
</html>
EOD;
if (!is_dir($archive_path . $temp_dir_short . '/document')) {
@mkdir($archive_path . $temp_dir_short . '/document', api_get_permissions_for_new_directories());
}
file_put_contents($archive_path . $temp_dir_short . '/document/non_exportable.html', $file_content);
// Add the extra files that go along with a SCORM package.
$main_code_path = api_get_path(SYS_CODE_PATH) . 'newscorm/packaging/';
$extra_files = scandir($main_code_path);
foreach ($extra_files as $extra_file) {
if (strpos($extra_file, '.') === 0) {
continue;
} else {
$dest_file = $archive_path . $temp_dir_short . '/' . $extra_file;
$this->create_path($dest_file);
copy($main_code_path . $extra_file, $dest_file);
}
}
// Finalize the imsmanifest structure, add to the zip, then return the zip.
$manifest = @$xmldoc->saveXML();
$manifest = api_utf8_decode_xml($manifest);
// The manifest gets the system encoding now.
file_put_contents($archive_path . '/' . $temp_dir_short . '/imsmanifest.xml', $manifest);
$zip_folder->add($archive_path . '/' . $temp_dir_short, PCLZIP_OPT_REMOVE_PATH, $archive_path . '/' . $temp_dir_short . '/');
// Clean possible temporary files.
foreach ($files_cleanup as $file) {
$res = unlink($file);
if ($res === false) {
error_log('Could not delete temp file ' . $file . ' ' . __FILE__ . ' ' . __LINE__, 0);
}
}
$name = api_replace_dangerous_char($this->get_name()) . '.zip';
DocumentManager::file_send_for_download($temp_zip_file, true, $name);
}
示例14: foreach
if (!$pub->is_accessible()) {
break;
}
if ($pub->is_file()) {
$items[] = $pub;
}
/**
* We ignore folders
*/
}
/**
* Requested files may not be accessible.
*/
if (count($items) == 0) {
Response::not_found();
}
/**
* Zip files together.
*/
$zip = Chamilo::temp_zip();
foreach ($items as $item) {
$path = $item->get_absolute_path();
$title = $item->get_title();
$zip->add($path, $title);
}
/**
* Send file for download
*/
event_download(Uri::here());
DocumentManager::file_send_for_download($zip->get_path(), false, get_lang('StudentPublications') . '.zip');
示例15: export_complete_report_xls
/**
* @param string $filename
* @param array $array
*/
function export_complete_report_xls($filename, $array)
{
global $global, $filter_score;
$spreadsheet = new PHPExcel();
$spreadsheet->setActiveSheetIndex(0);
$worksheet = $spreadsheet->getActiveSheet();
$line = 0;
$column = 0;
//skip the first column (row titles)
if ($global) {
$worksheet->SetCellValueByColumnAndRow($line, $column, get_lang('Courses'));
$column++;
$worksheet->SetCellValueByColumnAndRow($line, $column, get_lang('Exercises'));
$column++;
$worksheet->SetCellValueByColumnAndRow($line, $column, get_lang('ExamTaken'));
$column++;
$worksheet->SetCellValueByColumnAndRow($line, $column, get_lang('ExamNotTaken'));
$column++;
$worksheet->SetCellValueByColumnAndRow($line, $column, sprintf(get_lang('ExamPassX'), $filter_score) . '%');
$column++;
$worksheet->SetCellValueByColumnAndRow($line, $column, get_lang('ExamFail'));
$column++;
$worksheet->SetCellValueByColumnAndRow($line, $column, get_lang('TotalStudents'));
$column++;
$line++;
foreach ($array as $row) {
$column = 0;
foreach ($row as $item) {
$worksheet->SetCellValueByColumnAndRow($line, $column, html_entity_decode(strip_tags($item)));
$column++;
}
$line++;
}
$line++;
} else {
$worksheet->SetCellValueByColumnAndRow($line, $column, get_lang('Exercises'));
$column++;
$worksheet->SetCellValueByColumnAndRow($line, $column, get_lang('User'));
$column++;
$worksheet->SetCellValueByColumnAndRow($line, $column, get_lang('Percentage'));
$column++;
$worksheet->SetCellValueByColumnAndRow($line, $column, get_lang('Status'));
$column++;
$worksheet->SetCellValueByColumnAndRow($line, $column, get_lang('Attempts'));
$column++;
$line++;
foreach ($array as $row) {
$column = 0;
$worksheet->SetCellValueByColumnAndRow($line, $column, html_entity_decode(strip_tags($row['exercise'])));
$column++;
foreach ($row['users'] as $key => $user) {
$column = 1;
$worksheet->SetCellValueByColumnAndRow($line, $column, html_entity_decode(strip_tags($user)));
$column++;
foreach ($row['results'][$key] as $result_item) {
$worksheet->SetCellValueByColumnAndRow($line, $column, html_entity_decode(strip_tags($result_item)));
$column++;
}
$line++;
}
}
$line++;
}
$file = api_get_path(SYS_ARCHIVE_PATH) . api_replace_dangerous_char($filename);
$writer = new PHPExcel_Writer_Excel2007($spreadsheet);
$writer->save($file);
DocumentManager::file_send_for_download($file, true, $filename);
exit;
}