本文整理汇总了PHP中f::size方法的典型用法代码示例。如果您正苦于以下问题:PHP f::size方法的具体用法?PHP f::size怎么用?PHP f::size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类f
的用法示例。
在下文中一共展示了f::size方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: send
/**
* Sets up all curl options and sends the request
*
* @return object Response
*/
protected function send()
{
// start a curl request
$curl = curl_init();
// curl options
$params = array(CURLOPT_URL => $this->options['url'], CURLOPT_ENCODING => $this->options['encoding'], CURLOPT_CONNECTTIMEOUT => $this->options['timeout'], CURLOPT_TIMEOUT => $this->options['timeout'], CURLOPT_AUTOREFERER => true, CURLOPT_RETURNTRANSFER => $this->options['body'], CURLOPT_FOLLOWLOCATION => true, CURLOPT_MAXREDIRS => 10, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_HEADER => false, CURLOPT_HEADERFUNCTION => array($this, 'header'));
// add the progress
if (is_callable($this->options['progress'])) {
$params[CURLOPT_NOPROGRESS] = false;
$params[CURLOPT_PROGRESSFUNCTION] = $this->options['progress'];
}
// add all headers
if (!empty($this->options['headers'])) {
$params[CURLOPT_HTTPHEADER] = $this->options['headers'];
}
// add the user agent
if (!empty($this->options['agent'])) {
$params[CURLOPT_USERAGENT] = $this->options['agent'];
}
// do some request specific stuff
switch (strtolower($this->options['method'])) {
case 'post':
$params[CURLOPT_POST] = true;
$params[CURLOPT_POSTFIELDS] = $this->postfields($this->options['data']);
break;
case 'put':
$params[CURLOPT_CUSTOMREQUEST] = 'PUT';
$params[CURLOPT_POSTFIELDS] = $this->postfields($this->options['data']);
// put a file
if ($this->options['file']) {
$params[CURLOPT_INFILE] = fopen($this->options['file'], 'r');
$params[CURLOPT_INFILESIZE] = f::size($this->options['file']);
}
break;
case 'delete':
$params[CURLOPT_CUSTOMREQUEST] = 'DELETE';
$params[CURLOPT_POSTFIELDS] = $this->postfields($this->options['data']);
break;
case 'head':
$params[CURLOPT_CUSTOMREQUEST] = 'HEAD';
$params[CURLOPT_POSTFIELDS] = $this->postfields($this->options['data']);
$params[CURLOPT_NOBODY] = true;
break;
}
curl_setopt_array($curl, $params);
$content = curl_exec($curl);
$error = curl_errno($curl);
$message = curl_error($curl);
$info = curl_getinfo($curl);
curl_close($curl);
$this->response = new RemoteResponse();
$this->response->headers = $this->headers;
$this->response->error = $error;
$this->response->message = $message;
$this->response->content = $content;
$this->response->code = $info['http_code'];
$this->response->info = $info;
return $this->response;
}
示例2: info
function info()
{
if ($this->info) {
return $this->info;
}
$info = array('size' => f::size($this->root), 'mime' => function_exists('mime_content_type') ? @mime_content_type($this->root) : false);
// set the nice size
$info['niceSize'] = f::nice_size($info['size']);
return $this->info = new obj($info);
}
示例3: size
/**
* Returns the file size as integer
*
* @return int
*/
public function size()
{
return f::size($this->root);
}
示例4: size
/**
* Gets the size of the directory and all subfolders and files
*
* @param string $dir The path of the directory
* @param boolean $recursive
* @param boolean $nice returns the size in a human readable size
* @return mixed
*/
static function size($path, $recursive = true, $nice = false)
{
if (!file_exists($path)) {
return false;
}
if (is_file($path)) {
return self::size($path, $nice);
}
$size = 0;
foreach (glob($path . "/*") as $file) {
if ($file != "." && $file != "..") {
if ($recursive) {
$size += self::size($file, true);
} else {
$size += f::size($path);
}
}
}
return $nice ? f::nice_size($size) : $size;
}
示例5: size
/**
* Determines the size/length of numbers, strings, arrays and files
*
* @param mixed $value
* @return int
*/
function size($value)
{
if (is_numeric($value)) {
return $value;
}
if (is_string($value)) {
return str::length(trim($value));
}
if (is_array($value)) {
return count($value);
}
if (f::exists($value)) {
return f::size($value) / 1024;
}
}
示例6: download
public static function download($file, $name = null)
{
// stop the download if the file does not exist or is not readable
if (!is_file($file) or !is_readable($file)) {
return false;
}
header::download(array('name' => $name ? $name : f::filename($file), 'size' => f::size($file), 'mime' => f::mime($file), 'modified' => f::modified($file)));
die(f::read($file));
}
示例7: checkUpload
protected function checkUpload($file, $blueprint)
{
if (strtolower($file->extension()) == kirby()->option('content.file.extension', 'txt')) {
throw new Exception('Content files cannot be uploaded');
} else {
if (strtolower($file->extension()) == 'php' or str::contains($file->extension(), 'php') or in_array($file->mime(), f::$mimes['php'])) {
throw new Exception('PHP files cannot be uploaded');
} else {
if (strtolower($file->extension()) == 'html' or $file->mime() == 'text/html') {
throw new Exception('HTML files cannot be uploaded');
} else {
if (strtolower($file->extension()) == 'exe' or $file->mime() == 'application/x-msdownload') {
throw new Exception('EXE files cannot be uploaded');
} else {
if (strtolower($file->filename()) == '.htaccess') {
throw new Exception('htaccess files cannot be uploaded');
} else {
if (str::startsWith($file->filename(), '.')) {
throw new Exception('Invisible files cannot be uploaded');
// Files blueprint option 'type'
} else {
if (count($blueprint->files()->type()) > 0 and !in_array($file->type(), $blueprint->files()->type())) {
throw new Exception('Page only allows: ' . implode(', ', $blueprint->files()->type()));
// Files blueprint option 'size'
} else {
if ($blueprint->files()->size() and f::size($file->root()) > $blueprint->files()->size()) {
throw new Exception('Page only allows file size of ' . f::niceSize($blueprint->files()->size()));
// Files blueprint option 'width'
} else {
if ($file->type() == 'image' and $blueprint->files()->width() and $file->width() > $blueprint->files()->width()) {
throw new Exception('Page only allows image width of ' . $blueprint->files()->width() . 'px');
// Files blueprint option 'height'
} else {
if ($file->type() == 'image' and $blueprint->files()->height() and $file->height() > $blueprint->files()->height()) {
throw new Exception('Page only allows image height of ' . $blueprint->files()->height() . 'px');
}
}
}
}
}
}
}
}
}
}
}
示例8: checkUpload
public function checkUpload($file)
{
$filesettings = $this->blueprint->files();
$forbiddenExtensions = array('php', 'html', 'htm', 'exe', kirby()->option('content.file.extension', 'txt'));
$forbiddenMimes = array_merge(f::$mimes['php'], array('text/html', 'application/x-msdownload'));
$extension = strtolower($file->extension());
// files without extension are not allowed
if (empty($extension)) {
throw new Exception(l('files.add.error.extension.missing'));
}
// block forbidden extensions
if (in_array($extension, $forbiddenExtensions)) {
throw new Exception(l('files.add.error.extension.forbidden'));
}
// especially block any connection that contains php
if (str::contains($extension, 'php')) {
throw new Exception(l('files.add.error.extension.forbidden'));
}
// block forbidden mimes
if (in_array(strtolower($file->mime()), $forbiddenMimes)) {
throw new Exception(l('files.add.error.mime.forbidden'));
}
// Block htaccess files
if (strtolower($file->filename()) == '.htaccess') {
throw new Exception(l('files.add.error.htaccess'));
}
// Block invisible files
if (str::startsWith($file->filename(), '.')) {
throw new Exception(l('files.add.error.invisible'));
}
// Files blueprint option 'type'
if (count($filesettings->type()) > 0 and !in_array($file->type(), $filesettings->type())) {
throw new Exception(l('files.add.blueprint.type.error') . implode(', ', $filesettings->type()));
}
// Files blueprint option 'size'
if ($filesettings->size() and f::size($file->root()) > $filesettings->size()) {
throw new Exception(l('files.add.blueprint.size.error') . f::niceSize($filesettings->size()));
}
// Files blueprint option 'width'
if ($file->type() == 'image' and $filesettings->width() and $file->width() > $filesettings->width()) {
throw new Exception('Page only allows image width of ' . $filesettings->width() . 'px');
}
// Files blueprint option 'height'
if ($file->type() == 'image' and $filesettings->height() and $file->height() > $filesettings->height()) {
throw new Exception('Page only allows image height of ' . $filesettings->height() . 'px');
}
}
示例9: testSize
public function testSize()
{
$this->assertEquals(37, f::size($this->contentFile));
}