本文整理汇总了PHP中readfile函数的典型用法代码示例。如果您正苦于以下问题:PHP readfile函数的具体用法?PHP readfile怎么用?PHP readfile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了readfile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: down_sql_action
function down_sql_action()
{
$file = $this->config[sy_weburl] . "/data/backup/{$_GET['name']}";
header('Content-type: application/sql');
header('Content-Disposition: attachment; filename="' . $_GET[name] . '"');
readfile($file);
}
示例2: executeDownload
public function executeDownload(sfWebRequest $request)
{
$this->checkProject($request);
$this->checkProfile($request, $this->ei_project);
$this->checkAttachment($request);
//throw new Exception($this->ei_subject_attachment->getPath());
$filePath = sfConfig::get('sf_upload_dir') . '/subjectAttachements/' . $this->ei_subject_attachment->getPath();
//$mimeType = mime_content_type($this->ei_subject_attachment->getPath());
/** @var $response sfWebResponse */
$response = $this->getResponse();
$response->clearHttpHeaders();
//$response->setContentType($mimeType);
$response->setHttpHeader('Content-Disposition', 'attachment; filename="' . $this->ei_subject_attachment->getFileName() . '"');
$response->setHttpHeader('Content-Description', 'File Transfer');
$response->setHttpHeader('Content-Transfer-Encoding', 'binary');
$response->setHttpHeader('Content-Length', filesize($filePath));
$response->setHttpHeader('Cache-Control', 'public, must-revalidate');
// if https then always give a Pragma header like this to overwrite the "pragma: no-cache" header which
// will hint IE8 from caching the file during download and leads to a download error!!!
$response->setHttpHeader('Pragma', 'public');
//$response->setContent(file_get_contents($filePath)); # will produce a memory limit exhausted error
$response->sendHttpHeaders();
ob_end_flush();
return $this->renderText(readfile($filePath));
}
示例3: display
public function display($cachable = false, $urlparams = false)
{
JRequest::setVar('view', JRequest::getCmd('view', 'Orphans'));
if (isset($_POST['_orphanaction']) && $_POST['_orphanaction'] == "zipIt") {
$file = tempnam("tmp", "zip");
$zip = new ZipArchive();
$zip->open($file, ZipArchive::OVERWRITE);
foreach ($_POST['tozip'] as $_file) {
$zip->addFile(JPATH_ROOT . "/" . $_file, $_file);
}
$zip->close();
header('Content-Type: application/zip');
header('Content-Length: ' . filesize($file));
header('Content-Disposition: attachment; filename="orphans.zip"');
readfile($file);
unlink($file);
die;
} else {
if (isset($_POST['_orphanaction']) && $_POST['_orphanaction'] == "delete" && isset($_POST['_confirmAction'])) {
foreach ($_POST['tozip'] as $_file) {
unlink(JPATH_ROOT . "/" . $_file);
}
}
}
// call parent behavior
parent::display($cachable);
}
示例4: image
function image()
{
ob_end_clean();
$hash = basename($_REQUEST["hash"]);
if ($hash) {
$filename = $this->cache_dir . "/" . $hash . '.png';
if (file_exists($filename)) {
/* See if we can use X-Sendfile */
$xsendfile = false;
if (function_exists('apache_get_modules') && array_search('mod_xsendfile', apache_get_modules())) {
$xsendfile = true;
}
if ($xsendfile) {
header("X-Sendfile: {$filename}");
header("Content-type: application/octet-stream");
header('Content-Disposition: attachment; filename="' . basename($filename) . '"');
} else {
header("Content-type: image/png");
$stamp = gmdate("D, d M Y H:i:s", filemtime($filename)) . " GMT";
header("Last-Modified: {$stamp}", true);
readfile($filename);
}
} else {
header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found");
echo "File not found.";
}
}
}
示例5: display
public function display()
{
//parse image uri
$preset = $this->uri->segment(2);
$fileId = $this->uri->segment(3);
$file = new File($fileId);
if (!$file->isFileOfUser($this->c_user->id)) {
return false;
}
$imageFile = $file->image->get();
$updated = (string) $file->image->updated;
$manipulator = $this->get('core.image.manipulator');
if ($this->input->post()) {
$this->cropParamUpdate($file);
echo 'images/' . $preset . '/' . $fileId . '/' . $imageFile->updated . '?prev=' . $updated;
} else {
$path = FCPATH . $file->path . '/' . $file->fullname;
$output = $manipulator->getImagePreset($path, $preset, $imageFile, Arr::get($_GET, 'prev', null));
if ($output) {
$info = getimagesize($output);
header("Content-Disposition: filename={$output};");
header("Content-Type: {$info["mime"]}");
header('Content-Transfer-Encoding: binary');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');
readfile($output);
}
}
}
示例6: pageOpen
private function pageOpen()
{
?>
<!DOCTYPE html>
<html>
<head>
<title>Portfolio</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<?php
/* <link rel="stylesheet" href="/style.css"> */
?>
<style><?php
readfile(dirname(dirname(__DIR__)) . '/html/style.css');
?>
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.min.js"></script>
<script src="/tablesort.min.js"></script>
<script src="/tablesort.number.js"></script>
<script src="/script.js"></script>
</head>
<body>
<?php
}
示例7: stream
/**
* Stream a file to the browser, adding all the headings and fun stuff.
* Headers sent include: Content-type, Content-Length, Last-Modified,
* and Content-Disposition.
*
* @param string $fname Full name and path of the file to stream
* @param array $headers Any additional headers to send
* @param bool $sendErrors Send error messages if errors occur (like 404)
* @throws MWException
* @return bool Success
*/
public static function stream($fname, $headers = array(), $sendErrors = true)
{
wfProfileIn(__METHOD__);
if (FileBackend::isStoragePath($fname)) {
// sanity
wfProfileOut(__METHOD__);
throw new MWException(__FUNCTION__ . " given storage path '{$fname}'.");
}
wfSuppressWarnings();
$stat = stat($fname);
wfRestoreWarnings();
$res = self::prepareForStream($fname, $stat, $headers, $sendErrors);
if ($res == self::NOT_MODIFIED) {
$ok = true;
// use client cache
} elseif ($res == self::READY_STREAM) {
wfProfileIn(__METHOD__ . '-send');
$ok = readfile($fname);
wfProfileOut(__METHOD__ . '-send');
} else {
$ok = false;
// failed
}
wfProfileOut(__METHOD__);
return $ok;
}
示例8: GrabImage
public static function GrabImage($url, $filename = "")
{
if ($url == "") {
return false;
}
if ($filename == "") {
$ext = strrchr($url, ".");
if ($ext != ".gif" && $ext != ".jpg" && $ext != ".png") {
return false;
}
$filename = date("YmdHis") . $ext;
} else {
$newPath = dirname($filename);
DirectoryFile::dirCreate($newPath);
}
ob_start();
readfile($url);
$img = ob_get_contents();
ob_end_clean();
$size = strlen($img);
$fp2 = @fopen($filename, "a");
fwrite($fp2, $img);
fclose($fp2);
return $filename;
}
示例9: action_thumb
public function action_thumb()
{
if (!preg_match('/^image\\/.*$/i', $this->attachment['mime'])) {
$ext = File::ext_by_mime($this->attachment['mime']);
if (file_exists(DOCROOT . 'img/icons/' . $ext . '-icon-128x128.png')) {
$this->redirect('/img/icons/' . $ext . '-icon-128x128.png');
} else {
$this->redirect('http://stdicon.com/' . $this->attachment['mime'] . '?size=96&default=http://stdicon.com/text');
}
}
if (!file_exists(DOCROOT . 'storage/' . $this->attachment['id'] . '.thumb')) {
if (!file_exists(DOCROOT . 'storage/' . $this->attachment['id'])) {
$this->redirect('http://stdicon.com/' . $this->attachment['mime'] . '?size=96&default=http://stdicon.com/text');
}
$data = file_get_contents(DOCROOT . 'storage/' . $this->attachment['id']);
$image = imagecreatefromstring($data);
$x = imagesx($image);
$y = imagesy($image);
$size = max($x, $y);
$x = round($x / $size * 96);
$y = round($y / $size * 96);
$thumb = imagecreatetruecolor($x, $y);
imagealphablending($thumb, false);
imagesavealpha($thumb, true);
imagecopyresampled($thumb, $image, 0, 0, 0, 0, $x, $y, imagesx($image), imagesy($image));
imagepng($thumb, DOCROOT . 'storage/' . $this->attachment['id'] . '.thumb', 9);
}
header('Content-type: image/png');
header('Content-disposition: filename="thumbnail.png"');
header('Content-length: ' . filesize(DOCROOT . 'storage/' . $this->attachment['id'] . '.thumb'));
readfile(DOCROOT . 'storage/' . $this->attachment['id'] . '.thumb');
die;
}
示例10: export
function export($params = null)
{
$patients = $this->Patient->getPatients($params);
unset($this->Patient);
$zip = new ZipArchive();
$file = 'GaiaEHR-Patients-Export-' . time() . '.zip';
if ($zip->open($file, ZipArchive::CREATE) !== true) {
throw new Exception("cannot open <{$file}>");
}
$zip->addFromString('cda2.xsl', file_get_contents(ROOT . '/lib/CCRCDA/schema/cda2.xsl'));
foreach ($patients as $i => $patient) {
$patient = (object) $patient;
$this->CCDDocument->setPid($patient->pid);
$this->CCDDocument->createCCD();
$this->CCDDocument->setTemplate('toc');
$this->CCDDocument->createCCD();
$ccd = $this->CCDDocument->get();
$zip->addFromString($patient->pid . '-Patient-CDA' . '.xml', $ccd);
unset($patients[$i], $ccd);
}
$zip->close();
header('Content-Type: application/zip');
header('Content-Length: ' . filesize($file));
header('Content-Disposition: attachment; filename="' . $file . '"');
readfile($file);
}
示例11: dumpSPOG
function dumpSPOG()
{
header('Content-Type: application/sparql-results+xml');
if ($this->v('store_use_dump_dir', 0, $this->a)) {
$path = $this->v('store_dump_dir', 'dumps', $this->a);
/* default: monthly dumps */
$path_suffix = $this->v('store_dump_suffix', date('Y_m'), $this->a);
$path .= '/dump_' . $path_suffix . '.spog';
if (!file_exists($path)) {
$this->saveSPOG($path);
}
readfile($path);
exit;
}
echo $this->getHeader();
$offset = 0;
do {
$proceed = 0;
$rs = $this->getRecordset($offset);
if (!$rs) {
break;
}
while ($row = mysqli_fetch_array($rs)) {
echo $this->getEntry($row);
$proceed = 1;
}
$offset += $this->limit;
} while ($proceed);
echo $this->getFooter();
}
示例12: spamhurdles_spoken_captcha
/**
* This function will feed the $say parameter to a speech
* synthesizer and send the resulting audio file to the browser
*
* @param string $say
*/
function spamhurdles_spoken_captcha($say)
{
global $PHORUM;
$conf = $PHORUM["mod_spamhurdles"]["captcha"];
if ($conf["spoken_captcha"] && file_exists($conf["flite_location"])) {
// Generate the command for building the wav file.
$tmpfile = tempnam($PHORUM["cache"], 'spokencaptcha_');
$cmd = escapeshellcmd($conf["flite_location"]);
$cmd .= " -t " . escapeshellarg($say);
$cmd .= " -o " . escapeshellarg($tmpfile);
// Build the wav file.
system($cmd);
// Did we succeed in building the wav? Then stream it to the user.
if (file_exists($tmpfile) and filesize($tmpfile) > 0) {
header("Content-Type: audio/x-wav");
header("Content-Disposition: attachment; filename=captchacode.wav");
header("Content-Length: " . filesize($tmpfile));
readfile($tmpfile);
unlink($tmpfile);
exit(0);
// Something in the setup is apparently wrong here.
} else {
die("<h1>Internal Spam Hurdles module error</h1>" . "Failed to generate a wave file using flite.\n" . "Please contact the site maintainer to report this problem.");
}
} else {
die("<h1>Internal Spam Hurdles module error</h1>" . "Spoken captcha requested, but no spoken text is available\n" . "or the speech system has not been enabled/configured. " . "Please contact the site maintainer to report this problem.");
}
}
示例13: saveImage
/**
* Save the image as the image type the original image was
*
* @param string $savePath - The path to store the new image
* @param string $imageQuality - The qulaity level of image to create
*
* @param bool $download
*
* @return null Saves the image
*/
public function saveImage($savePath, $imageQuality = "100", $download = false)
{
if (!$this->newImage) {
return;
}
switch ($this->ext) {
case 'image/jpg':
case 'image/jpeg':
// Check PHP supports this file type
if (imagetypes() & IMG_JPG) {
imagejpeg($this->newImage, $savePath, $imageQuality);
}
break;
case 'image/gif':
// Check PHP supports this file type
if (imagetypes() & IMG_GIF) {
imagegif($this->newImage, $savePath);
}
break;
case 'image/png':
$invertScaleQuality = 9 - round($imageQuality / 100 * 9);
// Check PHP supports this file type
if (imagetypes() & IMG_PNG) {
imagepng($this->newImage, $savePath, $invertScaleQuality);
}
break;
}
if ($download) {
header('Content-Description: File Transfer');
header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename= " . $savePath . "");
readfile($savePath);
}
imagedestroy($this->newImage);
}
示例14: render
/**
* Display the application.
*/
public function render()
{
$user = JFactory::getUser();
$conf = JFactory::getConfig();
if ($user->guest || !JFactory::getUser()->authorise('core.admin', 'com_cache')) {
//TODO change this to the the proper access acl
echo JText::_('Unauthorized');
exit;
}
$logfile = $this->input->getPath('logfile', null);
if (is_null($logfile)) {
echo JText::_('Log not found.');
exit;
}
$logfile_path = JPATH_ROOT . '/logs/' . $logfile;
if (!is_file($logfile_path)) {
echo JText::_('Log not found.');
exit;
}
JResponse::clearHeaders();
header('Content-type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . pathinfo($logfile, PATHINFO_FILENAME) . '.log');
header('Content-Length: ' . filesize($logfile_path) . ';');
header('Content-Transfer-Encoding: binary');
readfile($logfile_path);
exit;
}
示例15: redirect
function redirect($filename)
{
Header("Content-Type: text/xml; charset=" . $this->encoding . "; filename=" . basename($filename));
Header("Content-Disposition: inline; filename=" . basename($filename));
readfile($filename, "r");
die;
}