function index() { $fn = substr($this->uri->uri_string(), 1); if (file_exists($fn)) { if (function_exists('apache_request_headers')) { $headers = apache_request_headers(); } // Checking if the client is validating his cache and if it is current. if (isset($headers['If-Modified-Since']) && strtotime($headers['If-Modified-Since']) == filemtime($fn)) { // Client's cache IS current, so we just respond '304 Not Modified'. header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($fn)) . ' GMT', true, 304); } else { // Image not cached or cache outdated, we respond '200 OK' and output the image. header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($fn)) . ' GMT', true, 200); header('Content-Length: ' . filesize($fn)); $this->load->helper('file'); $mime = get_mime_by_extension($fn); header('Content-Type: $mime'); print file_get_contents($fn); } } else { $this->output->set_header("HTTP/1.0 404 Not Found"); echo "Not found"; } }
function pic_thumb($pic_id) { $this->load->helper('file'); $this->load->library('image_lib'); $base_path = "uploads/item_pics/" . $pic_id; $images = glob($base_path . "*"); if (sizeof($images) > 0) { $image_path = $images[0]; $ext = pathinfo($image_path, PATHINFO_EXTENSION); $thumb_path = $base_path . $this->image_lib->thumb_marker . '.' . $ext; if (sizeof($images) < 2) { $config['image_library'] = 'gd2'; $config['source_image'] = $image_path; $config['maintain_ratio'] = TRUE; $config['create_thumb'] = TRUE; $config['width'] = 52; $config['height'] = 32; $this->image_lib->initialize($config); $image = $this->image_lib->resize(); $thumb_path = $this->image_lib->full_dst_path; } $this->output->set_content_type(get_mime_by_extension($thumb_path)); $this->output->set_output(file_get_contents($thumb_path)); } }
function get($filename) { $id = $this->input->get('id'); $token = $this->input->get('token'); //Chequeamos permisos del frontend $file = Doctrine_Query::create()->from('File f, f.Tramite t, t.Etapas e, e.Usuario u')->where('f.id = ? AND f.llave = ? AND u.id = ?', array($id, $token, UsuarioSesion::usuario()->id))->fetchOne(); if (!$file) { //Chequeamos permisos en el backend $file = Doctrine_Query::create()->from('File f, f.Tramite.Proceso.Cuenta.UsuariosBackend u')->where('f.id = ? AND f.llave = ? AND u.id = ? AND (u.rol="super" OR u.rol="operacion" OR u.rol="seguimiento")', array($id, $token, UsuarioBackendSesion::usuario()->id))->fetchOne(); if (!$file) { echo 'Usuario no tiene permisos para ver este archivo.'; exit; } } $path = 'uploads/documentos/' . $file->filename; if (preg_match('/^\\.\\./', $file->filename)) { echo 'Archivo invalido'; exit; } if (!file_exists($path)) { echo 'Archivo no existe'; exit; } $friendlyName = str_replace(' ', '-', convert_accented_characters(mb_convert_case($file->Tramite->Proceso->Cuenta->nombre . ' ' . $file->Tramite->Proceso->nombre, MB_CASE_LOWER) . '-' . $file->id)) . '.' . pathinfo($path, PATHINFO_EXTENSION); header('Content-Type: ' . get_mime_by_extension($path)); header('Content-Length: ' . filesize($path)); header('Content-Disposition: attachment; filename="' . $friendlyName . '"'); readfile($path); }
public function mime_type() { $ext = end(explode('.', $this->path)); if (in_array($ext, array('htm', 'html', 'php', 'phtml', 'php3', 'php4', 'php5', 'php5', 'php6'))) { return 'text/html'; } else { if (in_array($ext, array('js', 'jscript'))) { return 'text/javascript'; } else { if (in_array($ext, array('css', 'css3'))) { return 'text/css'; } else { if (in_array($ext, array('sql'))) { return 'text/plain'; } else { if (in_array($ext, array('jpg', 'jpeg', 'png', 'gif'))) { return 'image/' . str_replace('jpg', 'jpeg', $ext); } else { return get_mime_by_extension($this->path); } } } } } }
function __construct() { parent::__construct(); $this->load->library('uri'); $this->load->helper('file'); $segments = $this->uri->segment_array(); array_shift($segments); $path = APPPATH . '../assets'; foreach ($segments as $segment) { $path .= '/' . $segment; } if (realpath($path) !== false) { $data = read_file($path); if (php_sapi_name() == 'apache2handler' || php_sapi_name() == 'apache') { $headers = apache_request_headers(); if (isset($headers['If-Modified-Since']) && !empty($headers['If-Modified-Since'])) { header('Not Modified', true, 304); exit; } } header('Content-Type: ' . get_mime_by_extension(basename($path))); header('Cache-Control: max-age=3600, must-revalidate'); header('Last-Modified: ' . standard_date('DATE_COOKIE', filemtime($path))); echo $data; exit; } else { show_error('Asset does not exist in repository.', 404); } }
public function get($id_media) { // Pictures data from database $picture = $id_media ? $this->media_model->get($id_media) : FALSE; $options = $this->uri->uri_to_assoc(); unset($options['get']); if (empty($options['size'])) { $options['size'] = 120; } // Path to the picture if ($picture && file_exists($picture_path = DOCPATH . $picture['path'])) { $thumb_path = DOCPATH . Settings::get('files_path') . str_replace(Settings::get('files_path') . '/', '/.thumbs/', $picture['base_path']); $thumb_file_path = $this->medias->get_thumb_file_path($picture, $options); $refresh = !empty($options['refresh']) ? TRUE : FALSE; // If no thumb, try to create it if (!file_exists($thumb_file_path) or $refresh === TRUE) { try { $thumb_file_path = $this->medias->create_thumb(DOCPATH . $picture['path'], $thumb_file_path, $options); } catch (Exception $e) { // $return_thumb_path = FCPATH.'themes/'.Settings::get('theme_admin').'/styles/'.Settings::get('backend_ui_style').'/images/icon_48_no_folder_rights.png'; } } $mime = get_mime_by_extension($thumb_file_path); $content = read_file($thumb_file_path); $this->push_thumb($content, $mime, 0); } else { $mime = 'image/png'; $content = read_file(FCPATH . 'themes/' . Settings::get('theme_admin') . '/styles/' . Settings::get('backend_ui_style') . '/images/icon_48_no_source_picture.png'); $this->push_thumb($content, $mime, 0); } }
/** * Publishes a file to user. * This method will serve the original file or the browser cached version if available and uppon user settings * * @param string|null $file * * @return void * @throws 404 not found if the requested file does not exist. */ private function _serveFile($file = NULL) { if (!is_file($file)) { show_404('requested url is invalid'); } $Modified = filemtime($file); $gmdate_mod = gmdate('D, d M Y H:i:s', $Modified) . " GMT"; if ($this->_usecache) { if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { $if_modified_since = preg_replace('/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE']); if ($if_modified_since >= $gmdate_mod) { $this->CI->output->set_header('HTTP/1.1 304 Not Modified'); // HTTP/1.1 //header('HTTP/1.1 304 Not Modified'); $this->CI->we_are_done = TRUE; exit; } } //no cache found, so we serve original file } else { $this->CI->output->set_header("Cache-Control: no-cache, must-revalidate"); //Cache-Controle //header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 $this->CI->output->set_header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); //Date in the past // header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past } $mime = get_mime_by_extension($file); $this->CI->output->set_header("HTTP/1.0 200 OK")->set_header("HTTP/1.1 200 OK")->set_content_type($mime)->set_header('Last-Modified: ' . $gmdate_mod)->set_header('Content-Length: ' . filesize($file))->set_output(file_get_contents($file)); }
/** * Performs the image processing based on the parameters provided in the GET request * * @param string $file The name of the image to return. */ public function index() { // Quick before it's too late $this->output->enable_profiler(false); // routing doesn't work (?) $config = config_item('assets'); $request = $config['cache_path'] . str_replace(get_class($this) . '/', '', $this->uri->ruri_string()); $this->load->helper('file'); $output = false; if (empty($request) || !is_string($request)) { // Kill now! show_404(); } /*if($_output = $this->cache->file->get($request)) { $output = $_output; }*/ if ($_output = read_file(APPPATH . $request)) { $output = $_output; } if ($output) { $this->output->set_content_type(get_mime_by_extension($request))->set_output(trim($output)); } else { show_404(); } }
function datos_get($filename) { $id = $this->input->get('id'); $token = $this->input->get('token'); //Chequeamos los permisos en el frontend $file = Doctrine_Query::create()->from('File f, f.Tramite t, t.Etapas e, e.Usuario u')->where('f.id = ? AND f.llave = ? AND u.id = ?', array($id, $token, UsuarioSesion::usuario()->id))->fetchOne(); if (!$file) { //Chequeamos permisos en el backend $file = Doctrine_Query::create()->from('File f, f.Tramite.Proceso.Cuenta.UsuariosBackend u')->where('f.id = ? AND f.llave = ? AND u.id = ? AND (u.rol="super" OR u.rol="operacion" OR u.rol="seguimiento")', array($id, $token, UsuarioBackendSesion::usuario()->id))->fetchOne(); if (!$file) { echo 'Usuario no tiene permisos para ver este archivo.'; exit; } } $path = 'uploads/datos/' . $file->filename; if (preg_match('/^\\.\\./', $file->filename)) { echo 'Archivo invalido'; exit; } if (!file_exists($path)) { echo 'Archivo no existe'; exit; } header('Content-Type: ' . get_mime_by_extension($path)); header('Content-Length: ' . filesize($path)); readfile($path); }
function get($file) { if ($row = $this->downloads->get_doc(array('download_files.file' => $file))) { $fn = $this->downloads->settings['upload_path'] . $file; if (file_exists($fn)) { //counter hit if ($this->session->userdata('download_file' . $row['id']) != $row['id']) { $this->session->set_userdata('download_file' . $row['id'], $row['id']); $this->downloads->update_doc(array('hit' => $row['hit'] + 1), $row['id']); } if (function_exists('apache_request_headers')) { $headers = apache_request_headers(); } // Checking if the client is validating his cache and if it is current. if (isset($headers['If-Modified-Since']) && strtotime($headers['If-Modified-Since']) == filemtime($fn)) { // Client's cache IS current, so we just respond '304 Not Modified'. header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($fn)) . ' GMT', true, 304); } else { $this->load->helper('file'); // Image not cached or cache outdated, we respond '200 OK' and output the image. header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($fn)) . ' GMT', true, 200); header('Content-Length: ' . filesize($fn)); header('Content-Type: ' . get_mime_by_extension($file)); header("Content-Disposition: attachment; filename=\"{$file}\""); print file_get_contents($fn); } } else { $this->output->set_header("HTTP/1.0 404 Not Found"); $this->layout->load($this->template, '404'); } } else { $this->output->set_header("HTTP/1.0 404 Not Found"); $this->layout->load($this->template, '404'); } }
function set_output($type, $content) { $CI =& get_instance(); $CI->load->helper('file'); $mime = get_mime_by_extension('.' . $type); header('Content-type: ' . $mime); exit($content); }
private function downloadReports() { $resAjax = new Response_Ajax(); $this->load->library('library_jasperstarter'); $java_bin = Helper_Config::getBinaryJava(); $this->library_jasperstarter->setPathFolderOutput(BASEPATH . '../application/temp'); $this->library_jasperstarter->setPathJavaBin($java_bin); $this->library_jasperstarter->dbGeneric('org.firebirdsql.jdbc.FBDriver', 'jdbc:firebirdsql://localhost:3050/C:\\FireBird\\FTT\\DIGIFORTDB.FDB', 'SYSDBA', 'masterkey'); //$MY =& MY_Controller::get_instance(); $date_begin = $this->input->post('date_begin'); $date_end = $this->input->post('date_end'); $rpte_tipo = $this->input->post('rpte_tipo'); $rpte_grupo = $this->input->post('rpte_grupo'); try { $condicion = ' AND 1=1 '; if ($rpte_tipo == 'RPTE_CAMARAS_GENERAL') { $path_file_jasper = BASEPATH . "../application/reports/camaras_general/report.jasper"; $file_name_download = "CAMARA_EN_GENERAL"; $file_name_output = 'camaras_general_' . uniqid(); } else { if ($rpte_tipo == 'RPTE_GRUPOS_CAMARAS') { $path_file_jasper = BASEPATH . "../application/reports/grupos_general/rpte_grupos_general.jasper"; $file_name_download = "CAMARA_EN_GENERAL"; $file_name_output = 'camaras_general_' . uniqid(); //$condicion.=' AND 1=1'; foreach ($rpte_grupo as $key => $value) { $condicion .= "AND ( GRUPO_CAMARA = '" . $value . "' )"; } } else { throw new Exception('ERROR DE EJECCIÓN<br/> COMANDO: Tipo de reporte no encontrado'); } } $arrParameter = array('fecha_inicio' => $date_begin, 'fecha_fin' => $date_end, 'condicion' => $condicion); /* @var $oReport oReport */ $oReport = $this->library_jasperstarter->buildReport($path_file_jasper, $file_name_output, $arrParameter, 'xls'); if (!$oReport->isSuccess()) { throw new Exception('ERROR DE EJECCIÓN<br/> COMANDO: ' . $oReport->cmd()); } //$data = file_get_contents( $oReport->filePath() ); // Read the file's contents //force_download($file_name_output, $data); $mime = get_mime_by_extension($oReport->fileExtension()); //$mime = "application/pdf"; ob_clean(); header("Content-Type: application/force-download"); //header("Content-Disposition: attachment; filename=$file_name_download.xls"); header("Content-Transfer-Encoding: binary"); //header("Content-Length: " . $size); header("Content-disposition: attachment; filename={$file_name_download}.xls"); header("Content-type: {$mime}"); readfile($oReport->filePath()); } catch (Exception $err) { echo $err->getMessage(); } //echo $resAjax->toJsonEncode(); }
function view($tmp = '', $file = '', $type = 'pdf', $att = 0) { $filename = $tmp . "." . $type; if (file_exists($this->thisdir . "/output/" . $filename)) { $outfile = $file . "." . $type; header('Content-Disposition: ' . ($att == 1 ? 'attachment; ' : '') . 'filename="' . $outfile . '"'); header('Content-Type: ' . get_mime_by_extension($this->thisdir . "/output/" . $filename)); header('Content-Length: ' . filesize($this->thisdir . "/output/" . $filename)); header('Cache-Control: no-store'); readfile($this->thisdir . "/output/" . $filename); } }
function slides_get() { $uploadHandler = new UploadHandler($this->directory); $files = $this->slidesystem->listContents(); // echo '<pre>';print_r($files);die; $slideCounter = 1; $resource = new Collection($files, function (array $file) { return ['uri' => 'slides/' . $file['path'], 'mime' => get_mime_by_extension($file['path']), 'name' => $file['path'], 'path' => $file['filename'], 'timestamp' => $file['timestamp']]; }); $data = $this->fractal->createData($resource)->toArray(); $this->response($data); }
public function test_get_mime_by_extension() { $content = 'Jack and Jill went up the mountain to fight a billy goat.'; $file = vfsStream::newFile('my_file.txt', 0777)->withContent($content)->lastModified(time() - 86400)->at($this->_test_dir); $this->assertEquals('text/plain', get_mime_by_extension(vfsStream::url('my_file.txt'))); // Test a mime with an array, such as png $file = vfsStream::newFile('foo.png')->at($this->_test_dir); $this->assertEquals('image/png', get_mime_by_extension(vfsStream::url('foo.png'))); // Test a file not in the mimes array $file = vfsStream::newFile('foo.blarfengar')->at($this->_test_dir); $this->assertFalse(get_mime_by_extension(vfsStream::url('foo.blarfengar'))); }
public static function downloadReport($name_file_jasper, $arrParameter = array(), $name_pdf_output = 'file', $type_report = 'pdf') { $file_output = self::buildReport($name_file_jasper, $arrParameter, $type_report); if (empty($file_output)) { echo "Error al Generar PDF"; exit; } ob_clean(); $mime = get_mime_by_extension($type_report); header("Content-disposition: attachment; filename={$name_pdf_output}.{$type_report}"); header("Content-type: {$mime}"); readfile("{$file_output}"); }
public function import_files() { $this->load->helper(array('directory', 'file')); $_files = directory_map(FCPATH . 'data' . DS . 'import', 1); $_importUnique = uniqid('imp_', true); $_errorFiles = array(); if (count($_files) != 0) { for ($i = 0; $i < count($_files); $i++) { $_ext = pathinfo($_files[$i], PATHINFO_EXTENSION); $_ext = strtolower($_ext); $_fileName = pathinfo($_files[$i], PATHINFO_BASENAME); $_uniqueFile = uniqid('data_', true); $_source = FCPATH . 'data' . DS . 'import' . DS . $_files[$i]; $_destination = FCPATH . 'data' . DS . 'files' . DS . $_uniqueFile . '.' . $_ext; $_thumbsFolder = FCPATH . 'data' . DS . 'thumbs' . DS; if (rename($_source, $_destination)) { $_options = array('id' => NULL, 'fileUniqueID' => uniqid('file_', true), 'fileName' => $_files[$i], 'fileType' => get_mime_by_extension($_files[$i]), 'fileSize' => filesize($_destination), 'fileTime' => time(), 'fileUploadBy' => $this->session->userdata['userUnique'], 'fileByCustomer' => '0', 'fileNewName' => $_uniqueFile . '.' . $_ext, 'fileMD5' => md5_file($_destination), 'fileCounter' => 0, 'filePublic' => '0', 'fileImportID' => $_importUnique); $_import = $this->mImport->importFiles($_options); if ($_import) { $this->mGlobal->log(array('type' => "info", 'message' => "File {$_files[$i]} was imported successfully.", 'size' => filesize($_destination))); $this->load->library('image_lib'); $config = array('source_image' => $_destination, 'new_image' => $_thumbsFolder . $_uniqueFile . '.jpg', 'maintain_ratio' => true, 'width' => $this->mGlobal->getConfig('THUMB_X')->configVal, 'height' => $this->mGlobal->getConfig('THUMB_Y')->configVal); $this->image_lib->initialize($config); $this->image_lib->resize(); $this->image_lib->clear(); $config32 = array('source_image' => $_destination, 'new_image' => $_thumbsFolder . $_uniqueFile . '_32x32.jpg', 'maintain_ratio' => true, 'width' => '32', 'height' => '32'); $this->image_lib->initialize($config32); $this->image_lib->resize(); $this->image_lib->clear(); } else { $this->mGlobal->log(array('type' => "error", 'message' => "File {$_files[$i]} could not be added to database.", 'size' => filesize($_destination))); $_errorFiles[] = $_files[$i]; } } else { $this->mGlobal->log(array('type' => "error", 'message' => "File {$_files[$i]} could not be imported.", 'size' => filesize($_destination))); $_errorFiles[] = $_files[$i]; } } if (count($_errorFiles) == 0) { $_errortype = 'success'; $_errormsg = __('import_msg_successfiles'); } else { $_errortype = 'error'; $_errormsg = __('import_msg_errorfiles', array(implode(',', $_errorFiles))); } } else { $_errortype = 'error'; $_errormsg = __('import_msg_nofilesto'); } redirect('admin/import?errortype=' . $_errortype . '&errormsg=' . urlencode($_errormsg)); }
public function thumbnail_get() { $name = $this->query('name'); if (!$name) { $this->response(null, 400); } $file = FCPATH . STORY_PHOTO_THUMBNAIL_PATH . $name; header('Content-Type: ' . get_mime_by_extension($file)); if (file_exists($file)) { readfile($file); } else { $this->response(['error' => 'File does not exists.'], 404); } }
function download($id) { $media = new Mediapublic($id); $media->counter(); $this->load->helper('download'); $this->load->helper('file'); if (!get_mime_by_extension($media->file)) { redirect($media->file); } else { $data = file_get_contents(urldecode($media->file)); $name = basename(urldecode($media->file)); force_download($name, $data); } }
public function write_file($path, $data, $params = NULL) { $object = array('Bucket' => $this->path, 'Key' => $path, 'Body' => $data, 'ACL' => 'public-read'); if (isset($params['mime'])) { $object['ContentType'] = $params['mime']; } if (!isset($object['ContentType'])) { $mime = get_mime_by_extension($path); if ($mime !== FALSE) { $object['ContentType'] = $mime; } } $result = $this->s3->putObject($object); $this->url = $this->public_url . $path; return TRUE; }
function propriedades_arquivos($arquivo, $complemento = '') { $ci =& get_instance(); if (!file_exists($arquivo)) { return $dadosImagem['localizacao'] = false; } else { $arquivoDados = explode('/', $arquivo); $extension = substr(strrchr($arquivo, '.'), 1); if ($extension != null) { $ci->load->helper('file'); $mime = get_mime_by_extension($arquivo); if ($mime != false) { $mime2 = explode('/', get_mime_by_extension($arquivo)); } else { $mime2[0] = "desconhecido"; $mime2[1] = "desconhecido"; } } else { $mime2[0] = "desconhecido"; $mime2[1] = "desconhecido"; $mime = null; } } $ci->load->helper('file'); $size = get_file_info($arquivo, array('name', 'server_path', 'size', 'date', 'readable', 'writable', 'executable', 'fileperms')); $dadosImagem = array(); foreach ($size as $k => $v) { $dadosImagem[$complemento . $k] = $v; } $dadosImagem[$complemento . 'localizacao'] = true; $dadosImagem[$complemento . 'mime'] = $mime; $dadosImagem[$complemento . 'mimeTipo'] = isset($mime2[0]) ? $mime2[0] : ''; $dadosImagem[$complemento . 'mimeSub'] = isset($mime2[1]) ? $mime2[1] : ''; $dadosImagem[$complemento . 'arquivo_formatado'] = renomear_arquivos($arquivoDados[count($arquivoDados) - 1]); $dadosImagem[$complemento . 'date_formatado'] = date('Y-m-d H:i:s', $size['date']); if ($mime2[0] == 'image') { $propriedades = getimagesize($arquivo); $dadosImagem[$complemento . 'largura'] = $propriedades[0]; $dadosImagem[$complemento . 'altura'] = $propriedades[1]; } else { $dadosImagem[$complemento . 'largura'] = null; $dadosImagem[$complemento . 'altura'] = null; } return $dadosImagem; }
public function documento() { if ($this->input->get('id')) { $_POST['id'] = $this->input->get('id'); } if ($this->input->get('key')) { $_POST['key'] = $this->input->get('key'); } $this->form_validation->set_rules('id', 'Folio', 'required|callback_check_documento'); $this->form_validation->set_rules('key', 'Código de verificación', 'required'); if ($this->form_validation->run() == TRUE) { $file = Doctrine::getTable('File')->find($this->input->post('id')); $filename_copia = str_replace('.pdf', '.copia.pdf', $file->filename); $path = 'uploads/documentos/' . $filename_copia; header('Content-Type: ' . get_mime_by_extension($path)); header('Content-Length: ' . filesize($path)); readfile($path); } $this->load->view('validador/documento'); }
public function downloadFile() { $fileId = $this->uri->segment(3); $this->fileDataObj = new Document_Model($fileId); if ($this->fileDataObj->getError() != null or $this->fileDataObj->getStatus() > 0 or $this->fileDataObj->isArchived()) { $this->session->set_flashdata('error', 'There was an error downloading that file.'); redirect($_SERVER['HTTP_REFERRER']); exit; } $fileName = $this->config->item('dataDir') . $this->fileDataObj->getLocation(); $this->fileDataObj->modifyRights($this->uid); AccessLog_Model::addLogEntry($fileId, 'O'); AccessLog_Model::addLogEntry($fileId, 'D'); if (file_exists($fileName)) { header('Cache-control: private'); header('Content-Type: ' . get_mime_by_extension($fileName)); header('Content-Disposition: attachment; filename="' . $this->fileDataObj->getRealName() . '"'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); readfile($fileName); } }
/** * @brief 下载文件,默认在 UPLOAD 文件夹下 * * @param string $file * @param string $path 设定路径,默认为false * * @return */ public function download($file, $path = false) { if ($file) { if ($path) { $file = $path . $file; } else { $file = UPLOAD_PATH . $file; } } else { return false; } if (!file_exists($file)) { return false; } if (!function_exists('get_mime_by_extension')) { $CI =& get_instance(); $CI->load->helper('file'); } if ($type = get_mime_by_extension($file)) { $file_info = get_file_info($file); // ob_start(); // ini_set('memory_limit','1200M'); // set_time_limit(900); // // required for IE, otherwise Content-disposition is ignored // if(ini_get('zlib.output_compression')) // ini_set('zlib.output_compression', 'Off'); header("Content-Type:" . $type); header('Content-Disposition:attachment;filename=' . $file_info['name']); header('Content-Transfer-Encodeing: binary'); header('Content-Length:' . $file_info['size']); // ob_clean(); // flush(); readfile($file); exit; } else { log_message('debug', 'class download: can\'t find the file type'); return false; } }
function download_app($filename) { $this->load->helper("file"); if (file_exists($filename)) { @apache_setenv('no-gzip', 1); header('Content-Description: File Transfer'); header("Content-type: application/force-download"); header('Content-Type: ' . get_mime_by_extension($filename)); header('Content-Disposition: attachment; filename=' . basename($filename)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($filename)); ob_clean(); flush(); readfile($filename); exit; } else { show_404(); } }
function asset($file_path) { if (file_exists($file_path)) { $content = file_get_contents($file_path); $date = filemtime($file_path); } if (!isset($content)) { foreach (NeoFrag::loader()->paths['assets'] as $path) { if (!file_exists($path = $path . '/' . $file_path)) { continue; } $content = file_get_contents($path); $date = filemtime($path); break; } } if (isset($content)) { if (in_array($ext = extension($file_path), array('css', 'js'))) { $data = array('lang' => NeoFrag::loader()->config->lang); $content = NeoFrag::loader()->template->parse($content, $data); } ob_end_clean(); header('Last-Modified: ' . date('r', $date)); header('Etag: ' . ($etag = md5($content))); header('Content-Type: ' . get_mime_by_extension($ext)); if ($ext == 'zip') { header('Content-Disposition: attachment; filename="' . basename($file_path) . '"'); } if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $date || isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) { header('HTTP/1.1 304 Not Modified'); } else { header('HTTP/1.1 200 OK'); echo $content; } exit; } }
public function file_get($file_name) { $IB_id = $this->session->userdata('id_member'); //$client=$this->m_member->get_ib($file_name)->row(); //$granchild=$this->m_member->get_ib($client->id_refferer)->row(); if ($IB_id == $file_name) { // login check $file = 'media/img/member_id/id_card_' . $file_name . ".jpg"; if (is_file($file)) { // check the file is existing $this->load->helper('file'); header('Content-Type: ' . get_mime_by_extension($file)); readfile($file); } else { echo "error file"; } } else { echo "error"; } }
function directory_files_map($source_dir, $directory_depth = 0, $hidden = FALSE, $allowed_types = 'all') { $this->EE->load->helper('file'); if ($allowed_types == 'img') { $allowed_type = array('image/gif', 'image/jpeg', 'image/png'); } elseif ($allowed_types == 'all') { $allowed_type = array(); } if ($fp = @opendir($source_dir)) { $filedata = array(); $new_depth = $directory_depth - 1; $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; while (FALSE !== ($file = readdir($fp))) { // Remove '.', '..', and hidden files [optional] if (!trim($file, '.') or $hidden == FALSE && $file[0] == '.') { continue; } if (!@is_dir($source_dir . $file)) { if (!empty($allowed_type)) { $mime = get_mime_by_extension($file); //echo $mime; if (!in_array($mime, $allowed_type)) { continue; } } $filedata[] = $file; } } closedir($fp); sort($filedata); return $filedata; } return FALSE; }
public function getpicture() { $id = NULL; $type = NULL; //$url_pid = ''; $cr = 0; //return code $this->load->helper(array('printlist', 'file')); $this->load->helper('printerstoring'); $id = intval($this->input->get('id')); //return false if missing $type = $this->input->get('type'); //return false if missing if ($id && $type) { global $CFG; // $CI = &get_instance(); if ($type === "stl") { $image_file = $CFG->config['stl_library'] . sprintf('%06d', $id) . '/' . PRINTERSTORING_FILE_IMG_PNG; } else { if ($type === "gcode") { $image_file = $CFG->config['gcode_library'] . sprintf('%06d', $id) . '/' . PRINTERSTORING_FILE_IMG_JPG; } else { $this->_return_cr(ERROR_WRONG_PRM); return; } } // get img link from info file try { if (file_exists($image_file) === false) { $this->load->helper('printerlog'); PrinterLog_logError('model id not found', __FILE__, __LINE__); $this->_return_cr(ERROR_UNKNOWN_MODEL); return; } $this->output->set_content_type(get_mime_by_extension($image_file))->set_output(@file_get_contents($image_file)); return; } catch (Exception $e) { $CI->load->helper('printerlog'); PrinterLog_logError('could not get the picture', __FILE__, __LINE__); $this->_return_cr(ERROR_UNKNOWN_MODEL); return; } } else { $cr = ERROR_MISS_PRM; } $this->_return_cr($cr); return; }