本文整理汇总了PHP中OC_Filesystem::is_readable方法的典型用法代码示例。如果您正苦于以下问题:PHP OC_Filesystem::is_readable方法的具体用法?PHP OC_Filesystem::is_readable怎么用?PHP OC_Filesystem::is_readable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC_Filesystem
的用法示例。
在下文中一共展示了OC_Filesystem::is_readable方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
/**
* return the content of a file or return a zip file containning multiply files
*
* @param dir $dir
* @param file $file ; seperated list of files to download
*/
public static function get($dir, $files)
{
if (strpos($files, ';')) {
$files = explode(';', $files);
}
if (is_array($files)) {
$zip = new ZipArchive();
$filename = sys_get_temp_dir() . "/ownCloud.zip";
if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) {
exit("cannot open <{$filename}>\n");
}
foreach ($files as $file) {
$file = $dir . '/' . $file;
if (OC_Filesystem::is_file($file)) {
$tmpFile = OC_Filesystem::toTmpFile($file);
self::$tmpFiles[] = $tmpFile;
$zip->addFile($tmpFile, basename($file));
} elseif (OC_Filesystem::is_dir($file)) {
self::zipAddDir($file, $zip);
}
}
$zip->close();
} elseif (OC_Filesystem::is_dir($dir . '/' . $files)) {
$zip = new ZipArchive();
$filename = sys_get_temp_dir() . "/ownCloud.zip";
if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) {
exit("cannot open <{$filename}>\n");
}
$file = $dir . '/' . $files;
self::zipAddDir($file, $zip);
$zip->close();
} else {
$zip = false;
$filename = $dir . '/' . $files;
}
if ($zip or OC_Filesystem::is_readable($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');
if ($zip) {
header('Content-Type: application/zip');
header('Content-Length: ' . filesize($filename));
} else {
header('Content-Type: ' . OC_Filesystem::getMimeType($filename));
header('Content-Length: ' . OC_Filesystem::filesize($filename));
}
} elseif ($zip or !OC_Filesystem::file_exists($filename)) {
header("HTTP/1.0 404 Not Found");
$tmpl = new OC_Template('', '404', 'guest');
$tmpl->assign('file', $filename);
$tmpl->printPage();
// die('404 Not Found');
} else {
header("HTTP/1.0 403 Forbidden");
die('403 Forbidden');
}
@ob_end_clean();
if ($zip) {
readfile($filename);
unlink($filename);
} else {
OC_Filesystem::readfile($filename);
}
foreach (self::$tmpFiles as $tmpFile) {
if (file_exists($tmpFile) and is_file($tmpFile)) {
unlink($tmpFile);
}
}
}
示例2: get
/**
* return the content of a file or return a zip file containning multiply files
*
* @param dir $dir
* @param file $file ; seperated list of files to download
* @param boolean $only_header ; boolean to only send header of the request
*/
public static function get($dir, $files, $only_header = false)
{
if (strpos($files, ';')) {
$files = explode(';', $files);
}
if (is_array($files)) {
self::validateZipDownload($dir, $files);
$executionTime = intval(ini_get('max_execution_time'));
set_time_limit(0);
$zip = new ZipArchive();
$filename = OC_Helper::tmpFile('.zip');
if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== TRUE) {
exit("cannot open <{$filename}>\n");
}
foreach ($files as $file) {
$file = $dir . '/' . $file;
if (OC_Filesystem::is_file($file)) {
$tmpFile = OC_Filesystem::toTmpFile($file);
self::$tmpFiles[] = $tmpFile;
$zip->addFile($tmpFile, basename($file));
} elseif (OC_Filesystem::is_dir($file)) {
self::zipAddDir($file, $zip);
}
}
$zip->close();
set_time_limit($executionTime);
} elseif (OC_Filesystem::is_dir($dir . '/' . $files)) {
self::validateZipDownload($dir, $files);
$executionTime = intval(ini_get('max_execution_time'));
set_time_limit(0);
$zip = new ZipArchive();
$filename = OC_Helper::tmpFile('.zip');
if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== TRUE) {
exit("cannot open <{$filename}>\n");
}
$file = $dir . '/' . $files;
self::zipAddDir($file, $zip);
$zip->close();
set_time_limit($executionTime);
} else {
$zip = false;
$filename = $dir . '/' . $files;
}
@ob_end_clean();
if ($zip or OC_Filesystem::is_readable($filename)) {
header('Content-Disposition: attachment; filename="' . basename($filename) . '"');
header('Content-Transfer-Encoding: binary');
OC_Response::disableCaching();
if ($zip) {
ini_set('zlib.output_compression', 'off');
header('Content-Type: application/zip');
header('Content-Length: ' . filesize($filename));
} else {
$fileData = OC_FileCache::get($filename);
header('Content-Type: ' . $fileData['mimetype']);
}
} elseif ($zip or !OC_Filesystem::file_exists($filename)) {
header("HTTP/1.0 404 Not Found");
$tmpl = new OC_Template('', '404', 'guest');
$tmpl->assign('file', $filename);
$tmpl->printPage();
} else {
header("HTTP/1.0 403 Forbidden");
die('403 Forbidden');
}
if ($only_header) {
if (!$zip) {
header("Content-Length: " . OC_Filesystem::filesize($filename));
}
return;
}
if ($zip) {
$handle = fopen($filename, 'r');
if ($handle) {
$chunkSize = 8 * 1024;
// 1 MB chunks
while (!feof($handle)) {
echo fread($handle, $chunkSize);
flush();
}
}
unlink($filename);
} else {
OC_Filesystem::readfile($filename);
}
foreach (self::$tmpFiles as $tmpFile) {
if (file_exists($tmpFile) and is_file($tmpFile)) {
unlink($tmpFile);
}
}
}
示例3: fread
*
* Copyright 2013 EnginSoft S.p.A.
* All rights reserved
*/
$filename = $_POST['filename'];
$json = false;
if (isset($_POST['json'])) {
$json = (bool) $_POST["json"];
}
/*
* max size of output file, to avoid reading a very big output and clogging the network
*/
$MAX_SIZE = 1024 * 512;
# "512k of memory should be enough for everyone"
$content = "";
if (OC_Filesystem::is_file($filename) && OC_Filesystem::is_readable($filename)) {
if (OC_Filesystem::filesize($filename) > $MAX_SIZE) {
$handle = OC_Filesystem::fopen($filename, "r");
if ($handle) {
$content = fread($handle, $MAX_SIZE);
fclose($handle);
}
} else {
$content = OC_Filesystem::file_get_contents($filename);
}
} else {
echo "ERROR: Cannot read " . $filename;
}
if ($json) {
$json_obj = json_decode($content);
foreach ($json_obj as $key => $value) {