本文整理汇总了PHP中Idno\Entities\File类的典型用法代码示例。如果您正苦于以下问题:PHP File类的具体用法?PHP File怎么用?PHP File使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了File类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getContent
function getContent()
{
if (!empty($this->arguments[0])) {
$object = \Idno\Entities\File::getByID($this->arguments[0]);
}
if (empty($object)) {
$this->forward();
}
// TODO: 404
$headers = apache_request_headers();
if (isset($headers['If-Modified-Since'])) {
if (strtotime($headers['If-Modified-Since']) < time() - 600) {
header('HTTP/1.1 304 Not Modified');
exit;
}
}
header("Pragma: public");
header('Expires: ' . date(\DateTime::RFC1123, time() + 86400 * 365));
// Cache files for a year!
if (!empty($object->file['mime_type'])) {
header('Content-type: ' . $object->file['mime_type']);
} else {
header('Content-type: application/data');
}
echo $object->getBytes();
}
示例2: post
function post()
{
if (\Idno\Core\Idno::site()->session()->isLoggedOn()) {
if (!empty($_FILES['file']['tmp_name'])) {
if (!\Idno\Core\Idno::site()->triggerEvent("file/upload", [], true)) {
exit;
}
if (\Idno\Entities\File::isImage($_FILES['file']['tmp_name'])) {
$return = false;
$file = false;
if ($file = \Idno\Entities\File::createThumbnailFromFile($_FILES['file']['tmp_name'], $_FILES['file']['name'], 1024)) {
$return = true;
$returnfile = new \stdClass();
$returnfile->file = ['_id' => $file];
$file = $returnfile;
} else {
if ($file = \Idno\Entities\File::createFromFile($_FILES['file']['tmp_name'], $_FILES['file']['name'], $_FILES['file']['type'], true)) {
$return = true;
}
}
if ($return) {
$t = \Idno\Core\Idno::site()->template();
$t->file = $file;
echo $t->draw('file/picker/donejs');
exit;
}
} else {
Idno::site()->session()->addErrorMessage("You can only upload images.");
}
}
$this->forward($_SERVER['HTTP_REDIRECT']);
}
}
示例3: saveDataFromInput
/**
* Saves changes to this object based on user input
* @return bool
*/
function saveDataFromInput()
{
if (empty($this->_id)) {
$new = true;
} else {
$new = false;
}
$this->title = \Idno\Core\site()->currentPage()->getInput('title');
$this->body = \Idno\Core\site()->currentPage()->getInput('body');
$this->tags = \Idno\Core\site()->currentPage()->getInput('tags');
$this->setAccess('PUBLIC');
if ($time = \Idno\Core\site()->currentPage()->getInput('created')) {
if ($time = strtotime($time)) {
$this->created = $time;
}
}
// Get photo
if ($new) {
if (!empty($_FILES['photo']['tmp_name'])) {
if (\Idno\Entities\File::isImage($_FILES['photo']['tmp_name'])) {
if ($photo = \Idno\Entities\File::createFromFile($_FILES['photo']['tmp_name'], $_FILES['photo']['name'], $_FILES['photo']['type'], true)) {
$this->attachFile($photo);
// Now get some smaller thumbnails, with the option to override sizes
$sizes = \Idno\Core\site()->events()->dispatch('photo/thumbnail/getsizes', new \Idno\Core\Event(array('sizes' => ['large' => 800, 'medium' => 400, 'small' => 200])));
foreach ($sizes->data()['sizes'] as $label => $size) {
$filename = $_FILES['photo']['name'];
// Experiment: let's not save thumbnails for GIFs, in order to enable animated GIF posting.
if ($_FILES['photo']['type'] != 'image/gif') {
if ($thumbnail = \Idno\Entities\File::createThumbnailFromFile($_FILES['photo']['tmp_name'], "{$filename}_{$label}", $size)) {
$varname = "thumbnail_{$label}";
$this->{$varname} = \Idno\Core\site()->config()->url . 'file/' . $thumbnail;
$varname = "thumbnail_{$label}_id";
$this->{$varname} = substr($thumbnail, 0, strpos($thumbnail, '/'));
}
}
}
} else {
\Idno\Core\site()->session()->addMessage('Image wasn\'t attached.');
}
} else {
\Idno\Core\site()->session()->addMessage('This doesn\'t seem to be an image ..');
}
} else {
\Idno\Core\site()->session()->addMessage('We couldn\'t access your image. Please try again.');
return false;
}
}
if ($this->save()) {
if ($new) {
$this->addToFeed();
}
// Add it to the Activity Streams feed
\Idno\Core\Webmention::pingMentions($this->getURL(), \Idno\Core\site()->template()->parseURLs($this->getTitle() . ' ' . $this->getDescription()));
return true;
} else {
return false;
}
}
示例4: getContent
function getContent()
{
// Check modified ts
if ($cache = \Idno\Core\Idno::site()->cache()) {
if ($modifiedts = $cache->load("{$this->arguments[0]}_modified_ts")) {
$this->lastModifiedGatekeeper($modifiedts);
// Set 304 and exit if we've not modified this object
}
}
if (!empty($this->arguments[0])) {
$object = \Idno\Entities\File::getByID($this->arguments[0]);
}
if (empty($object)) {
$this->noContent();
}
session_write_close();
// Close the session early
//header("Pragma: public");
// Determine uploaded timestamp
if ($object instanceof \MongoGridFSFile) {
$upload_ts = $object->file['uploadDate']->sec;
} else {
if (!empty($object->updated)) {
$upload_ts = $object->updated;
} else {
if (!empty($object->created)) {
$upload_ts = $object->created;
} else {
$upload_ts = time();
}
}
}
header("Pragma: public");
header("Cache-Control: public");
header('Expires: ' . date(\DateTime::RFC1123, time() + 86400 * 30));
// Cache files for 30 days!
$this->setLastModifiedHeader($upload_ts);
if ($cache = \Idno\Core\Idno::site()->cache()) {
$cache->store("{$this->arguments[0]}_modified_ts", $upload_ts);
}
if (!empty($object->file['mime_type'])) {
header('Content-type: ' . $object->file['mime_type']);
} else {
header('Content-type: application/data');
}
//header('Accept-Ranges: bytes');
//header('Content-Length: ' . filesize($object->getSize()));
if (is_callable(array($object, 'passThroughBytes'))) {
$object->passThroughBytes();
} else {
if ($stream = $object->getResource()) {
while (!feof($stream)) {
echo fread($stream, 8192);
}
}
}
}
示例5: getContent
function getContent()
{
if (!empty($this->arguments[0])) {
$object = \Idno\Entities\File::getByID($this->arguments[0]);
}
if (empty($object)) {
$this->forward();
}
// TODO: 404
session_write_close();
// Close the session early
//header("Pragma: public");
// Determine uploaded timestamp
if ($object instanceof \MongoGridFSFile) {
$upload_ts = $object->file['uploadDate']->sec;
} else {
if (!empty($object->updated)) {
$upload_ts = $object->updated;
} else {
if (!empty($object->created)) {
$upload_ts = $object->created;
} else {
$upload_ts = time();
}
}
}
header("Pragma: public");
header("Cache-Control: public");
header('Expires: ' . date(\DateTime::RFC1123, time() + 86400 * 30));
// Cache files for 30 days!
$this->setLastModifiedHeader($upload_ts);
if (!empty($object->file['mime_type'])) {
header('Content-type: ' . $object->file['mime_type']);
} else {
header('Content-type: application/data');
}
//header('Accept-Ranges: bytes');
//header('Content-Length: ' . filesize($object->getSize()));
$headers = $this->getallheaders();
if (isset($headers['If-Modified-Since'])) {
if (strtotime($headers['If-Modified-Since']) <= $upload_ts) {
//> time() - (86400 * 30)) {
header('HTTP/1.1 304 Not Modified');
exit;
}
}
if (is_callable(array($object, 'passThroughBytes'))) {
$object->passThroughBytes();
} else {
if ($stream = $object->getResource()) {
while (!feof($stream)) {
echo fread($stream, 8192);
}
}
}
}
示例6: postContent
function postContent()
{
$this->adminGatekeeper();
// Flag that a site export has been requested
\Idno\Core\Idno::site()->config()->export_last_requested = time();
\Idno\Core\Idno::site()->config()->export_in_progress = 1;
\Idno\Core\Idno::site()->config()->save();
$this->forward(\Idno\Core\Idno::site()->config()->getDisplayURL() . 'admin/export/', false);
ignore_user_abort(true);
// This is dangerous, but we need export to continue
session_write_close();
header('Connection: close');
header('Content-length: ' . (string) ob_get_length());
@ob_end_flush();
// Return output to the browser
@ob_end_clean();
@flush();
sleep(10);
// Pause
set_time_limit(0);
// Eliminate time limit - this could take a while
// Remove the previous export file
if (!empty(\Idno\Core\Idno::site()->config()->export_file_id)) {
if ($file = File::getByID(\Idno\Core\Idno::site()->config()->export_file_id)) {
$file->remove();
\Idno\Core\Idno::site()->config()->export_file_id = false;
\Idno\Core\Idno::site()->config()->export_filename = false;
\Idno\Core\Idno::site()->config()->save();
}
}
if ($path = Migration::createCompressedArchive()) {
$filename = \Idno\Core\Idno::site()->config()->host . '.zip';
/* header('Content-disposition: attachment;filename=' . $filename);
if ($fp = fopen($path, 'r')) {
while ($content = fread($fp, 4096)) {
echo $content;
}
}
fclose($fp);*/
if ($file = File::createFromFile($path, $filename)) {
@unlink($path);
\Idno\Core\Idno::site()->config()->export_filename = $filename;
\Idno\Core\Idno::site()->config()->export_file_id = $file;
\Idno\Core\Idno::site()->config()->export_in_progress = 0;
\Idno\Core\Idno::site()->config()->save();
$mail = new Email();
$mail->setHTMLBodyFromTemplate('admin/export');
$mail->setTextBodyFromTemplate('admin/export');
$mail->addTo(\Idno\Core\Idno::site()->session()->currentUser()->email);
$mail->setSubject("Your data export is ready");
$mail->send();
}
exit;
}
}
示例7: post
function post()
{
if (\Idno\Core\site()->session()->isLoggedOn()) {
if (!empty($_FILES['file']['tmp_name'])) {
if ($file = \Idno\Entities\File::createFromFile($_FILES['file']['tmp_name'], $_FILES['file']['name'], $_FILES['file']['type'], true)) {
echo json_encode(\Idno\Core\site()->config()->url . 'file/' . $file->file['_id']);
error_log(\Idno\Core\site()->config()->url . 'file/' . $file->file['_id']);
}
}
}
}
示例8: post
function post()
{
if (\Idno\Core\site()->session()->isLoggedOn()) {
if (!empty($_FILES['file']['tmp_name'])) {
if (!\Idno\Core\site()->triggerEvent("file/upload", [], true)) {
exit;
}
if ($file = \Idno\Entities\File::createFromFile($_FILES['file']['tmp_name'], $_FILES['file']['name'], $_FILES['file']['type'], true, true)) {
echo json_encode(\Idno\Core\site()->config()->url . 'file/' . $file->file['_id']);
}
}
}
}
示例9: postContent
function postContent()
{
$this->adminGatekeeper();
// Admins only
if ($profile_user = $this->getInput('profile_user')) {
\Idno\Core\Idno::site()->config->config['cherwell']['profile_user'] = $profile_user;
}
if (!empty($_FILES['background']) && $this->getInput('action') != 'clear') {
if (in_array($_FILES['background']['type'], array('image/png', 'image/jpg', 'image/jpeg', 'image/gif'))) {
if (getimagesize($_FILES['background']['tmp_name'])) {
if ($background = \Idno\Entities\File::createFromFile($_FILES['background']['tmp_name'], $_FILES['background']['name'])) {
// Remove previous bg
if (!empty(\Idno\Core\Idno::site()->config()->cherwell['bg_id'])) {
if ($file = File::getByID(\Idno\Core\Idno::site()->config()->cherwell['bg_id'])) {
if (is_callable([$file, 'delete'])) {
// TODO: really need some abstraction here.
$file->delete();
} else {
if (is_callable([$file, 'remove'])) {
$file->remove();
}
}
}
}
\Idno\Core\Idno::site()->config->config['cherwell']['bg_id'] = $background;
$background = \Idno\Core\Idno::site()->config()->getDisplayURL() . 'file/' . $background;
\Idno\Core\Idno::site()->config->config['cherwell']['bg'] = $background;
}
}
}
} else {
// Remove previous bg
if (!empty(\Idno\Core\Idno::site()->config()->cherwell['bg_id'])) {
if ($file = File::getByID(\Idno\Core\Idno::site()->config()->cherwell['bg_id'])) {
if (is_callable([$file, 'delete'])) {
$file->delete();
} else {
if (is_callable([$file, 'remove'])) {
$file->remove();
}
}
}
}
\Idno\Core\Idno::site()->config->cherwell = [];
}
\Idno\Core\Idno::site()->config->save();
$this->forward(\Idno\Core\Idno::site()->config()->getDisplayURL() . 'admin/cherwell/');
}
示例10: post
function post()
{
if (\Idno\Core\site()->session()->isLoggedOn()) {
if (!empty($_FILES['file']['tmp_name'])) {
if (!\Idno\Core\site()->triggerEvent("file/upload", [], true)) {
exit;
}
if ($file = \Idno\Entities\File::createFromFile($_FILES['file']['tmp_name'], $_FILES['file']['name'], $_FILES['file']['type'], true)) {
$t = \Idno\Core\site()->template();
$t->file = $file;
echo $t->draw('file/picker/donejs');
exit;
}
}
}
}
示例11: saveDataFromInput
function saveDataFromInput()
{
if (empty($this->_id)) {
$new = true;
} else {
$new = false;
}
if ($new) {
if (!\Idno\Core\Idno::site()->triggerEvent("file/upload", [], true)) {
return false;
}
}
$body = \Idno\Core\Idno::site()->currentPage()->getInput('body');
if (!empty($_FILES['comic']['tmp_name']) || !empty($this->_id)) {
$this->body = $body;
$this->title = \Idno\Core\Idno::site()->currentPage()->getInput('title');
$this->description = \Idno\Core\Idno::site()->currentPage()->getInput('description');
if ($time = \Idno\Core\Idno::site()->currentPage()->getInput('created')) {
if ($time = strtotime($time)) {
$this->created = $time;
}
}
if (!empty($_FILES['comic']['tmp_name'])) {
if (\Idno\Entities\File::isImage($_FILES['comic']['tmp_name'])) {
if ($size = getimagesize($_FILES['comic']['tmp_name'])) {
$this->width = $size[0];
$this->height = $size[1];
}
if ($comic = \Idno\Entities\File::createFromFile($_FILES['comic']['tmp_name'], $_FILES['comic']['name'], $_FILES['comic']['type'], true)) {
$this->attachFile($comic);
}
}
}
$this->setAccess(\Idno\Core\Idno::site()->currentPage()->getInput('access', 'PUBLIC'));
if ($this->save($new)) {
if ($this->getAccess() == 'PUBLIC') {
\Idno\Core\Webmention::pingMentions($this->getURL(), \Idno\Core\Idno::site()->template()->parseURLs($this->getDescription()));
}
return true;
}
} else {
\Idno\Core\Idno::site()->session()->addErrorMessage('You can\'t save an empty comic.');
}
return false;
}
示例12: getContent
function getContent()
{
if (!empty($this->arguments[0])) {
$object = \Idno\Entities\File::getByID($this->arguments[0]);
}
if (empty($object)) {
$this->forward();
}
// TODO: 404
if (!function_exists('getallheaders')) {
function getallheaders()
{
$headers = '';
foreach ($_SERVER as $name => $value) {
if (substr($name, 0, 5) == 'HTTP_') {
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
}
}
return $headers;
}
}
$headers = getallheaders();
if (isset($headers['If-Modified-Since'])) {
if (strtotime($headers['If-Modified-Since']) < time() - 600) {
header('HTTP/1.1 304 Not Modified');
exit;
}
}
//header("Pragma: public");
header('Expires: ' . date(\DateTime::RFC1123, time() + 86400 * 30));
// Cache files for 30 days!
if (!empty($object->file['mime_type'])) {
header('Content-type: ' . $object->file['mime_type']);
} else {
header('Content-type: application/data');
}
//header('Accept-Ranges: bytes');
//header('Content-Length: ' . filesize($object->getSize()));
if (is_callable([$object, 'passThroughBytes'])) {
$object->passThroughBytes();
} else {
echo $object->getBytes();
}
}
示例13: saveDataFromInput
/**
* Saves changes to this object based on user input
* @return bool
*/
function saveDataFromInput()
{
if (empty($this->_id)) {
$new = true;
} else {
$new = false;
}
$this->title = \Idno\Core\site()->currentPage()->getInput('title');
$this->body = \Idno\Core\site()->currentPage()->getInput('body');
$this->setAccess('PUBLIC');
// Get photo
if ($new) {
if (!empty($_FILES['photo']['tmp_name'])) {
if (\Idno\Entities\File::isImage($_FILES['photo']['tmp_name'])) {
if ($photo = \Idno\Entities\File::createFromFile($_FILES['photo']['tmp_name'], $_FILES['photo']['name'], $_FILES['photo']['type'], true)) {
$this->attachFile($photo);
if ($thumbnail = \Idno\Entities\File::createThumbnailFromFile($_FILES['photo']['tmp_name'], $_FILES['photo']['name'])) {
$this->thumbnail = \Idno\Core\site()->config()->url . 'file/' . $thumbnail;
$this->thumbnail_id = substr($thumbnail, 0, strpos($thumbnail, '/'));
}
} else {
\Idno\Core\site()->session()->addMessage('Image wasn\'t attached.');
}
} else {
\Idno\Core\site()->session()->addMessage('This doesn\'t seem to be an image ..');
}
} else {
\Idno\Core\site()->session()->addMessage('We couldn\'t access your image. Please try again.');
return false;
}
}
if ($this->save()) {
if ($new) {
$this->addToFeed();
}
// Add it to the Activity Streams feed
\Idno\Core\Webmention::pingMentions($this->getURL(), \Idno\Core\site()->template()->parseURLs($this->getDescription()));
\Idno\Core\site()->session()->addMessage('Your photo was successfully saved.');
return true;
} else {
return false;
}
}
示例14: saveDataFromInput
function saveDataFromInput()
{
if (empty($this->_id)) {
$new = true;
} else {
$new = false;
}
$body = \Idno\Core\site()->currentPage()->getInput('body');
if (!empty($_FILES['comic']['tmp_name']) || !empty($this->_id)) {
$this->body = $body;
$this->title = \Idno\Core\site()->currentPage()->getInput('title');
$this->description = \Idno\Core\site()->currentPage()->getInput('description');
if ($time = \Idno\Core\site()->currentPage()->getInput('created')) {
if ($time = strtotime($time)) {
$this->created = $time;
}
}
if (!empty($_FILES['comic']['tmp_name'])) {
if (\Idno\Entities\File::isImage($_FILES['comic']['tmp_name'])) {
if ($size = getimagesize($_FILES['comic']['tmp_name'])) {
$this->width = $size[0];
$this->height = $size[1];
}
if ($comic = \Idno\Entities\File::createFromFile($_FILES['comic']['tmp_name'], $_FILES['comic']['name'], $_FILES['comic']['type'], true)) {
$this->attachFile($comic);
}
}
}
$this->setAccess('PUBLIC');
if ($this->save()) {
if ($new) {
// Add it to the Activity Streams feed
$this->addToFeed();
}
\Idno\Core\Webmention::pingMentions($this->getURL(), \Idno\Core\site()->template()->parseURLs($this->getDescription()));
return true;
}
} else {
\Idno\Core\site()->session()->addMessage('You can\'t save an empty comic.');
}
return false;
}
示例15: postContent
function postContent()
{
$this->gatekeeper();
// Logged-in only please
$user = \Idno\Core\site()->session()->currentUser();
$name = $this->getInput('name');
//$handle = $this->getInput('handle');
$email = $this->getInput('email');
$password = $this->getInput('password');
$password2 = $this->getInput('password2');
if (!empty($name)) {
$user->setTitle($name);
}
if (!empty($email) && $email != $user->email && filter_var($email, FILTER_VALIDATE_EMAIL)) {
if (!\Idno\Entities\User::getByEmail($email)) {
$user->email = $email;
} else {
\Idno\Core\site()->session()->addMessage('Someone is already using ' . $email . ' as their email address.', 'alert-error');
}
}
if (!empty($password) && $password == $password2) {
$user->setPassword($password);
}
if (!empty($_FILES['avatar'])) {
if (in_array($_FILES['avatar']['type'], array('image/png', 'image/jpg', 'image/jpeg', 'image/gif'))) {
if (getimagesize($_FILES['avatar']['tmp_name'])) {
if ($icon = \Idno\Entities\File::createThumbnailFromFile($_FILES['avatar']['tmp_name'], $_FILES['avatar']['name'], 300)) {
$user->icon = (string) $icon;
} else {
if ($icon = \Idno\Entities\File::createFromFile($_FILES['avatar']['tmp_name'], $_FILES['avatar']['name'])) {
$user->icon = (string) $icon;
}
}
}
}
}
if ($user->save()) {
\Idno\Core\site()->session()->addMessage("Your details were saved.");
}
$this->forward($_SERVER['HTTP_REFERER']);
}