예제 #1
0
 /**
  * Export tabular data to CSV-file
  * @param array $data
  * @param string $filename
  */
 public static function export_table_csv_utf8($data, $filename = 'export')
 {
     if (empty($data)) {
         return false;
     }
     $path = Chamilo::temp_file();
     $converter = new Utf8Encoder(null, true);
     $file = FileWriter::create($path, $converter);
     $file = CsvWriter::create($file);
     foreach ($data as $row) {
         $file->put($row);
     }
     $file->close();
     DocumentManager::file_send_for_download($path, false, $filename . '.csv');
     unlink($path);
     exit;
 }
예제 #2
0
 */
if (count($files) == 0) {
    Response::not_found();
}
$root_dir = '';
$items = array_merge($folders, $files);
foreach ($items as $item) {
    $path = $item->get_absolute_path();
    $path = realpath($path);
    $dir = dirname($path);
    if (empty($root_dir) || strlen($root_dir) > strlen($dir)) {
        $root_dir = $dir;
    }
}
/**
 * Zip files together.
 */
$temp_zip_path = Chamilo::temp_file('zip');
$zip_folder = new PclZip($temp_zip_path);
foreach ($files as $file) {
    if (empty($root_dir)) {
        $root_dir = dirname($file);
    }
    $file = (string) $file;
    $zip_folder->add($file, PCLZIP_OPT_REMOVE_PATH, $root_dir);
}
/**
 * Send file for download
 */
event_download(Uri::here());
DocumentManager::file_send_for_download($temp_zip_path, false, get_lang('Documents') . '.zip');