if (count($array) == 0) { return null; } $df = fopen("file1.csv", 'w'); fwrite($df, ""); fputcsv($df, $titles, ';'); foreach ($array as $row) { fputcsv($df, $row, ';'); } fclose($df); } $titles = array("Категория", "Значение"); $data = array(array('Сумма всех посещений', $arrow[0]), array('Посещения библиотеки', $arrow[1]), array('Сумма Справок', $arrow[0]), array('Количество консультаций', $docs_array[3]), array('Удаленное обслуживание', $docs_array[2]), array('Искандэр', $docs_array[0]), array('Кипарис', $docs_array[1]), array('Правовые справочные системы', $docs_array[2]), array('Консультант+:', $arrow[3]), array('Правовые Базы:', $arrow[4])); array2csv($data, $titles); if (isset($_POST['export_csv'])) { file_force_download('file1.csv'); } ?> <form action="" method="post"> <input type="submit" name="export_csv" value="Скачать" class="form-control" id="save"> </form> <input type="button" value="Печать" class="form-control" id="print" > </form> <script> $("#print").on('click', function () { window.print();
//заполняем данными из БД foreach ($records as $fields) { fputcsv($csv, $fields, ';'); } fclose($csv); break; } function file_force_download($file) { if (file_exists($file)) { // сбрасываем буфер вывода PHP, чтобы избежать переполнения памяти выделенной под скрипт // если этого не сделать файл будет читаться в память полностью! if (ob_get_level()) { ob_end_clean(); } // заставляем браузер показать окно сохранения файла //header('Content-Description: File Transfer'); // header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . basename($file)); //header('Content-Transfer-Encoding: binary'); // header('Expires: 0'); //header('Cache-Control: must-revalidate'); // header('Pragma: public'); // header('Content-Length: ' . filesize($file)); // читаем файл и отправляем его пользователю readfile($file); exit; } } file_force_download($newFileName);
$panel = "<div id='panel'><a href='?download'>download</a></a>"; $eventName = $modx->event->name; switch ($eventName) { case 'OnPageNotFound': if ($modx->context->key == 'mgr') { return; } $file_name = preg_replace(array("/\\?(.*)/", "/\\//"), '', $_SERVER['REQUEST_URI']); $SERVER_NAME = $name_virtual_file ? $name_virtual_file : $_SERVER['SERVER_NAME']; if ($modx->user->isMember($members) && $file_name == $SERVER_NAME) { $dir = $_SERVER['DOCUMENT_ROOT'] . $dir . $_SERVER['SERVER_NAME'] . '.send'; if (file_exists($dir)) { $file = file_get_contents($dir); $file = iconv('windows-1251', 'utf-8', $file); if (isset($_GET['download'])) { file_force_download($file); } echo "<em>version " . $version . "</em>"; echo $panel; echo '<pre>' . $file . '</pre>'; exit; } } break; } function file_force_download($content) { global $name_virtual_file; header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . basename($name_virtual_file));
header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); // читаем файл и отправляем его пользователю if ($fd = fopen($file, 'rb')) { while (!feof($fd)) { print fread($fd, 1024); } fclose($fd); } exit; } } //Модная функция пушинга файла в браузер. Туда придет бинарный blob, который форсом выдается в браузер-даунлоад через JS file_force_download($tobrowser); imagedestroy($im); imagedestroy($srcimg); imagedestroy($pattern); imagedestroy($tomerge); imagedestroy($pattern_src); imagedestroy($srcimg_src); //====================================================================== } else { header('Content-Disposition: attachment; filename=NOFILE.php'); header("HTTP/1.0 404 Not Found"); exit('NO FILES'); } ?> ; exit('NO FILES');
<?php /* imgsave.php модуль содержит функцию file_force_download для сохранения файла формата png на стороне клиента входной параметр - путь к файлу на сервере */ session_start(); $filename = urldecode(filter_input(INPUT_GET, 'fname')); file_force_download($filename); exit; function file_force_download($file) { if (file_exists($file)) { // сбрасываем буфер вывода PHP, чтобы избежать переполнения памяти выделенной под скрипт // если этого не сделать файл будет читаться в память полностью! if (ob_get_level()) { ob_end_clean(); } // заставляем браузер показать окно сохранения файла header('Content-Description: File Transfer'); header('Content-Type: image/png'); header('Content-Disposition: attachment; filename=' . basename($file)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); // читаем файл и отправляем его пользователю if ($fd = fopen($file, 'rb')) { while (!feof($fd)) { print fread($fd, 1024);
<?php include_once "functions/functions.php"; if (isset($_GET['fileid'])) { connect_db(); $query = mysql_query("SELECT COUNT(*) as count FROM `messages` WHERE `fileId` = " . mysql_real_escape_string($_GET['fileid']) . " AND `idUserOwner` = " . $_SESSION['userId']); $result = mysql_fetch_assoc($query)['count']; if ($result <= 0) { die("This is not your file!"); } $query = mysql_query("SELECT * FROM `files` WHERE `id` = " . mysql_real_escape_string($_GET['fileid'])); $fileInfo = mysql_fetch_assoc($query); file_force_download("./files/" . $fileInfo['path'], $fileInfo['filename']); }
<?php include 'wideimage/WideImage.php'; include '../../vendor/autoload.php'; use PHPImageWorkshop\ImageWorkshop; $imageURL = $_POST['main-image-file']; $watermarkURL = $_POST['watermark-file']; $positionX = $_POST['x']; $positionY = $_POST['y']; $opacity = $_POST['opacity'] * 100; $image = ImageWorkshop::initFromPath($imageURL); $watermark = ImageWorkshop::initFromPath($watermarkURL); $watermark->opacity($opacity); $image->addLayer(1, $watermark, $positionX, $positionY, "LT"); $image->save(__DIR__, 'result.jpg', true, null, 95); file_force_download(__DIR__ . '/result.jpg'); exit; function file_force_download($result) { if (file_exists($result)) { /*if (ob_get_level()) { ob_end_clean(); }*/ //header('Content-Description: File Transfer'); //header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . basename($result)); //header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate'); //header('Pragma: public'); //header('Content-Length: ' . filesize($result));