本文整理汇总了PHP中AttachmentFile类的典型用法代码示例。如果您正苦于以下问题:PHP AttachmentFile类的具体用法?PHP AttachmentFile怎么用?PHP AttachmentFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AttachmentFile类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: getFile
function getFile()
{
if (!$this->file && $this->getFileId()) {
$this->file = AttachmentFile::lookup($this->getFileId());
}
return $this->file;
}
开发者ID:pkdevboxy,项目名称:osTicket-1.7,代码行数:7,代码来源:class.attachment.php
示例2: syncExistingAttachments
function syncExistingAttachments()
{
$matches = array();
if (!preg_match_all('/"cid:([\\w.-]{32})"/', $this->getBody(), $matches)) {
return;
}
// Purge current attachments
$this->attachments->deleteInlines();
foreach ($matches[1] as $hash) {
if ($file = AttachmentFile::getIdByHash($hash)) {
$this->attachments->upload($file, true);
}
}
}
开发者ID:KingsleyGU,项目名称:osticket,代码行数:14,代码来源:class.draft.php
示例3: run
function run($runtime)
{
$errors = array();
$i18n = new Internationalization('en_US');
$tpls = $i18n->getTemplate('email_template_group.yaml')->getData();
foreach ($tpls as $t) {
// If the email template group specifies an id attribute, remove
// it for upgrade because we cannot assume that the id slot is
// available
unset($t['id']);
EmailTemplateGroup::create($t, $errors);
}
$files = $i18n->getTemplate('file.yaml')->getData();
foreach ($files as $f) {
$id = AttachmentFile::create($f, $errors);
// Ensure the new files are never deleted (attached to Disk)
$sql = 'INSERT INTO ' . ATTACHMENT_TABLE . ' SET object_id=0, `type`=\'D\', inline=1' . ', file_id=' . db_input($id);
db_query($sql);
}
}
开发者ID:dmiguel92,项目名称:osTicket-1.8,代码行数:20,代码来源:d51f303a-dad45ca2.task.php
示例4: next
/**
* Processes the next item on the work queue. Emits a JSON messages to
* indicate current progress.
*
* Returns:
* TRUE/NULL if the migration was successful
*/
function next()
{
# Fetch next item -- use the last item so the array indices don't
# need to be recalculated for every shift() operation.
$info = array_pop($this->queue);
# Attach file to the ticket
if (!($info['data'] = @file_get_contents($info['path']))) {
# Continue with next file
return $this->skip($info['attachId'], sprintf('%s: Cannot read file contents', $info['path']));
}
# Get the mime/type of each file
# XXX: Use finfo_buffer for PHP 5.3+
if (function_exists('mime_content_type')) {
//XXX: function depreciated in newer versions of PHP!!!!!
$info['type'] = mime_content_type($info['path']);
} elseif (function_exists('finfo_file')) {
// PHP 5.3.0+
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$info['type'] = finfo_file($finfo, $info['path']);
}
# TODO: Add extension-based mime-type lookup
if (!($fileId = AttachmentFile::save($info))) {
return $this->skip($info['attachId'], sprintf('%s: Unable to migrate attachment', $info['path']));
}
# Update the ATTACHMENT_TABLE record to set file_id
db_query('update ' . TICKET_ATTACHMENT_TABLE . ' set file_id=' . db_input($fileId) . ' where attach_id=' . db_input($info['attachId']));
# Remove disk image of the file. If this fails, the migration for
# this file would not be retried, because the file_id in the
# TICKET_ATTACHMENT_TABLE has a nonzero value now
if (!@unlink($info['path'])) {
//XXX: what should we do on failure?
$this->error(sprintf('%s: Unable to remove file from disk', $info['path']));
}
# TODO: Log an internal note to the ticket?
return true;
}
开发者ID:nunomartins,项目名称:osTicket-1.7,代码行数:43,代码来源:class.migrater.php
示例5: next
/**
* Processes the next item on the work queue. Emits a JSON messages to
* indicate current progress.
*
* Returns:
* TRUE/NULL if the migration was successful
*/
function next()
{
# Fetch next item -- use the last item so the array indices don't
# need to be recalculated for every shift() operation.
$info = array_pop($this->queue);
# Attach file to the ticket
if (!($info['data'] = @file_get_contents($info['path']))) {
# Continue with next file
return $this->error(sprintf('%s: Cannot read file contents', $info['path']));
}
# Get the mime/type of each file
# XXX: Use finfo_buffer for PHP 5.3+
$info['type'] = mime_content_type($info['path']);
if (!($fileId = AttachmentFile::save($info))) {
return $this->error(sprintf('%s: Unable to migrate attachment', $info['path']));
}
# Update the ATTACHMENT_TABLE record to set file_id
db_query('update ' . TICKET_ATTACHMENT_TABLE . ' set file_id=' . db_input($fileId) . ' where attach_id=' . db_input($info['attachId']));
# Remove disk image of the file. If this fails, the migration for
# this file would not be retried, because the file_id in the
# TICKET_ATTACHMENT_TABLE has a nonzero value now
if (!@unlink($info['path'])) {
$this->error(sprintf('%s: Unable to remove file from disk', $info['path']));
}
# TODO: Log an internal note to the ticket?
return true;
}
开发者ID:nicolap,项目名称:osTicket-1.7,代码行数:34,代码来源:class.attachment.migrate.php
示例6: Copyright
file.php
File download facilitator for clients
Peter Rotich <[email protected]>
Jared Hancock <[email protected]>
Copyright (c) 2006-2014 osTicket
http://www.osticket.com
Released under the GNU General Public License WITHOUT ANY WARRANTY.
See LICENSE.TXT for details.
vim: expandtab sw=4 ts=4 sts=4:
**********************************************************************/
require 'client.inc.php';
require_once INCLUDE_DIR . 'class.file.php';
//Basic checks
if (!$_GET['key'] || !$_GET['signature'] || !$_GET['expires'] || !($file = AttachmentFile::lookup($_GET['key']))) {
Http::response(404, __('Unknown or invalid file'));
}
// Validate session access hash - we want to make sure the link is FRESH!
// and the user has access to the parent ticket!!
if ($file->verifySignature($_GET['signature'], $_GET['expires'])) {
if (($s = @$_GET['s']) && strpos($file->getType(), 'image/') === 0) {
return $file->display($s);
}
// Download the file..
$file->download(@$_GET['disposition'] ?: false, $_GET['expires']);
}
// else
Http::response(404, __('Unknown or invalid file'));
开发者ID:dmiguel92,项目名称:osTicket-1.8,代码行数:31,代码来源:file.php
示例7: send
function send($to, $subject, $message, $options = null)
{
global $ost;
//Get the goodies
require_once PEAR_DIR . 'Mail.php';
// PEAR Mail package
require_once PEAR_DIR . 'Mail/mime.php';
// PEAR Mail_Mime packge
//do some cleanup
$to = preg_replace("/(\r\n|\r|\n)/s", '', trim($to));
$subject = stripslashes(preg_replace("/(\r\n|\r|\n)/s", '', trim($subject)));
$body = stripslashes(preg_replace("/(\r\n|\r)/s", "\n", trim($message)));
/* Message ID - generated for each outgoing email */
$messageId = sprintf('<%s%d-%s>', Misc::randCode(6), time(), $this->getEmail() ? $this->getEmail()->getEmail() : '@osTicketMailer');
$headers = array('From' => $this->getFromAddress(), 'To' => $to, 'Subject' => $subject, 'Date' => date('D, d M Y H:i:s O'), 'Message-ID' => $messageId, 'X-Mailer' => 'osTicket Mailer', 'Content-Type' => 'text/html; charset="UTF-8"');
$mime = new Mail_mime();
$mime->setTXTBody($body);
//XXX: Attachments
if ($attachments = $this->getAttachments()) {
foreach ($attachments as $attachment) {
if ($attachment['file_id'] && ($file = AttachmentFile::lookup($attachment['file_id']))) {
$mime->addAttachment($file->getData(), $file->getType(), $file->getName(), false);
} elseif ($attachment['file'] && file_exists($attachment['file']) && is_readable($attachment['file'])) {
$mime->addAttachment($attachment['file'], $attachment['type'], $attachment['name']);
}
}
}
//Desired encodings...
$encodings = array('head_encoding' => 'quoted-printable', 'text_encoding' => 'quoted-printable', 'html_encoding' => 'base64', 'html_charset' => 'utf-8', 'text_charset' => 'utf-8', 'head_charset' => 'utf-8');
//encode the body
$body = $mime->get($encodings);
//encode the headers.
$headers = $mime->headers($headers);
if ($smtp = $this->getSMTPInfo()) {
//Send via SMTP
$mail = mail::factory('smtp', array('host' => $smtp['host'], 'port' => $smtp['port'], 'auth' => $smtp['auth'], 'username' => $smtp['username'], 'password' => $smtp['password'], 'timeout' => 20, 'debug' => false));
$result = $mail->send($to, $headers, $body);
if (!PEAR::isError($result)) {
return $messageId;
}
$alert = sprintf("Unable to email via SMTP:%s:%d [%s]\n\n%s\n", $smtp['host'], $smtp['port'], $smtp['username'], $result->getMessage());
$this->logError($alert);
}
//No SMTP or it failed....use php's native mail function.
$mail = mail::factory('mail');
return PEAR::isError($mail->send($to, $headers, $body)) ? false : $messageId;
}
开发者ID:nunomartins,项目名称:osTicket-1.7,代码行数:47,代码来源:class.mailer.php
示例8: deleteAttachments
function deleteAttachments()
{
$deleted = 0;
// Clear reference table
$res = db_query('DELETE FROM ' . TICKET_ATTACHMENT_TABLE . ' WHERE ticket_id=' . db_input($this->getId()));
if ($res && db_affected_rows()) {
$deleted = AttachmentFile::deleteOrphans();
}
return $deleted;
}
开发者ID:nicolap,项目名称:osTicket-1.7,代码行数:10,代码来源:class.ticket.php
示例9: foreach
data-signature="<?php
echo Format::htmlchars(Format::viewableImages($signature)); ?>"
data-signature-field="signature" data-dept-field="deptId"
placeholder="Intial response for the ticket"
name="response" id="response" cols="21" rows="8"
style="width:80%;"><?php echo $info['response']; ?></textarea>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<?php
if($cfg->allowAttachments()) { ?>
<tr><td width="100" valign="top">Attachments:</td>
<td>
<div class="canned_attachments">
<?php
if($info['cannedattachments']) {
foreach($info['cannedattachments'] as $k=>$id) {
if(!($file=AttachmentFile::lookup($id))) continue;
$hash=$file->getKey().md5($file->getId().session_id().$file->getKey());
echo sprintf('<label><input type="checkbox" name="cannedattachments[]"
id="f%d" value="%d" checked="checked"
<a href="file.php?h=%s">%s</a> </label> ',
$file->getId(), $file->getId() , $hash, $file->getName());
}
}
?>
</div>
<div class="uploads"></div>
<div class="file_input">
<input type="file" class="multifile" name="attachments[]" size="30" value="" />
</div>
</td>
</tr>
开发者ID:Jride,项目名称:OSTicket-Thaiconnections,代码行数:31,代码来源:ticket-open.inc.php
示例10: Copyright
<?php
/*********************************************************************
image.php
Simply downloads the file...on hash validation as follows;
* Hash must be 64 chars long.
* First 32 chars is the perm. file hash
* Next 32 chars is md5(file_id.session_id().file_hash)
Peter Rotich <[email protected]>
Copyright (c) 2006-2013 osTicket
http://www.osticket.com
Released under the GNU General Public License WITHOUT ANY WARRANTY.
See LICENSE.TXT for details.
vim: expandtab sw=4 ts=4 sts=4:
**********************************************************************/
require 'staff.inc.php';
require_once INCLUDE_DIR . 'class.file.php';
$h = trim($_GET['h']);
//basic checks
if (!$h || strlen($h) != 64 || !($file = AttachmentFile::lookup(substr($h, 0, 32))) || strcasecmp($h, $file->getDownloadHash())) {
//next 32 is file id + session hash.
die('Unknown or invalid file. #' . Format::htmlchars($_GET['h']));
}
$file->display();
开发者ID:pkdevboxy,项目名称:osTicket-1.7,代码行数:29,代码来源:image.php
示例11: deleteAttachments
function deleteAttachments()
{
global $cfg;
$deleted = 0;
if ($attachments = $this->getAttachments()) {
//Clear reference table - XXX: some attachments might be orphaned
db_query('DELETE FROM ' . TICKET_ATTACHMENT_TABLE . ' WHERE ticket_id=' . db_input($this->getId()));
//Delete file from DB IF NOT inuse.
foreach ($attachments as $attachment) {
if (($file = AttachmentFile::lookup($attachment['file_id'])) && !$file->isInuse() && $file->delete()) {
$deleted++;
}
}
}
return $deleted;
}
开发者ID:ryan1432,项目名称:osTicket-1.7fork,代码行数:16,代码来源:class.ticket.php
示例12: getValue
function getValue()
{
$data = $this->field->getSource();
$ids = array();
// Handle manual uploads (IE<10)
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_FILES[$this->name])) {
foreach (AttachmentFile::format($_FILES[$this->name]) as $file) {
try {
$ids[] = $this->field->uploadFile($file);
} catch (FileUploadError $ex) {
}
}
return array_merge($ids, parent::getValue() ?: array());
} elseif ($data && is_array($data) && !isset($data[$this->name])) {
return array();
}
return parent::getValue();
}
开发者ID:gizur,项目名称:osticket,代码行数:18,代码来源:class.forms.php
示例13: viewableImages
function viewableImages($html, $script = false)
{
return preg_replace_callback('/"cid:([\\w._-]{32})"/', function ($match) use($script) {
$hash = $match[1];
if (!($file = AttachmentFile::lookup($hash))) {
return $match[0];
}
return sprintf('"%s" data-cid="%s"', $file->getDownloadUrl(false, 'inline', $script), $match[1]);
}, $html);
}
开发者ID:gizur,项目名称:osticket,代码行数:10,代码来源:class.format.php
示例14: send
function send($to, $subject, $message, $options = null)
{
global $ost;
//Get the goodies
require_once PEAR_DIR . 'Mail.php';
// PEAR Mail package
require_once PEAR_DIR . 'Mail/mime.php';
// PEAR Mail_Mime packge
//do some cleanup
$to = preg_replace("/(\r\n|\r|\n)/s", '', trim($to));
$subject = preg_replace("/(\r\n|\r|\n)/s", '', trim($subject));
//We're decoding html entities here becasuse we only support plain text for now - html support comming.
$body = Format::htmldecode(preg_replace("/(\r\n|\r)/s", "\n", trim($message)));
/* Message ID - generated for each outgoing email */
$messageId = sprintf('<%s%d-%s>', Misc::randCode(6), time(), $this->getEmail() ? $this->getEmail()->getEmail() : '@osTicketMailer');
$headers = array('From' => $this->getFromAddress(), 'To' => $to, 'Subject' => $subject, 'Date' => date('D, d M Y H:i:s O'), 'Message-ID' => $messageId, 'X-Mailer' => 'osTicket Mailer');
//Set bulk/auto-response headers.
if ($options && ($options['autoreply'] or $options['bulk'])) {
$headers += array('X-Autoreply' => 'yes', 'X-Auto-Response-Suppress' => 'ALL, AutoReply', 'Auto-Submitted' => 'auto-replied');
if ($options['bulk']) {
$headers += array('Precedence' => 'bulk');
} else {
$headers += array('Precedence' => 'auto_reply');
}
}
if ($options) {
if (isset($options['inreplyto']) && $options['inreplyto']) {
$headers += array('In-Reply-To' => $options['inreplyto']);
}
if (isset($options['references']) && $options['references']) {
if (is_array($options['references'])) {
$headers += array('References' => implode(' ', $options['references']));
} else {
$headers += array('References' => $options['references']);
}
}
}
$mime = new Mail_mime();
$mime->setTXTBody($body);
//XXX: Attachments
if ($attachments = $this->getAttachments()) {
foreach ($attachments as $attachment) {
if ($attachment['file_id'] && ($file = AttachmentFile::lookup($attachment['file_id']))) {
$mime->addAttachment($file->getData(), $file->getType(), $file->getName(), false);
} elseif ($attachment['file'] && file_exists($attachment['file']) && is_readable($attachment['file'])) {
$mime->addAttachment($attachment['file'], $attachment['type'], $attachment['name']);
}
}
}
//Desired encodings...
$encodings = array('head_encoding' => 'quoted-printable', 'text_encoding' => 'base64', 'html_encoding' => 'base64', 'html_charset' => 'utf-8', 'text_charset' => 'utf-8', 'head_charset' => 'utf-8');
//encode the body
$body = $mime->get($encodings);
//encode the headers.
$headers = $mime->headers($headers, true);
if ($smtp = $this->getSMTPInfo()) {
//Send via SMTP
$mail = mail::factory('smtp', array('host' => $smtp['host'], 'port' => $smtp['port'], 'auth' => $smtp['auth'], 'username' => $smtp['username'], 'password' => $smtp['password'], 'timeout' => 20, 'debug' => false));
$result = $mail->send($to, $headers, $body);
if (!PEAR::isError($result)) {
return $messageId;
}
$alert = sprintf("Unable to email via SMTP:%s:%d [%s]\n\n%s\n", $smtp['host'], $smtp['port'], $smtp['username'], $result->getMessage());
$this->logError($alert);
}
//No SMTP or it failed....use php's native mail function.
$mail = mail::factory('mail');
return PEAR::isError($mail->send($to, $headers, $body)) ? false : $messageId;
}
开发者ID:pkdevboxy,项目名称:osTicket-1.7,代码行数:69,代码来源:class.mailer.php
示例15: deleteAttachments
function deleteAttachments()
{
$deleted = 0;
$sql = 'DELETE FROM ' . FAQ_ATTACHMENT_TABLE . ' WHERE faq_id=' . db_input($this->getId());
if (db_query($sql) && db_affected_rows()) {
$deleted = AttachmentFile::deleteOrphans();
}
return $deleted;
}
开发者ID:nunomartins,项目名称:osTicket-1.7,代码行数:9,代码来源:class.faq.php
示例16: save
function save($info, $inline = true)
{
if (!($fileId = AttachmentFile::save($info))) {
return false;
}
$sql = 'INSERT INTO ' . ATTACHMENT_TABLE . ' SET `type`=' . db_input($this->getType()) . ',object_id=' . db_input($this->getId()) . ',file_id=' . db_input($fileId) . ',inline=' . db_input($inline ? 1 : 0);
if (!db_query($sql) || !db_affected_rows()) {
return false;
}
return $fileId;
}
开发者ID:ed00m,项目名称:osTicket-1.8,代码行数:11,代码来源:class.attachment.php
示例17: savefile
public function savefile($uid, $original_file_path, $original_basename, $file_name = NULL, $file_ext = NULL, $description = NULL)
{
if (!file_exists($original_file_path)) {
return FALSE;
}
is_null($file_ext) && ($file_ext = strtolower(pathinfo($original_basename, PATHINFO_EXTENSION)));
is_null($file_name) && ($file_name = mb_basename($original_basename, '.' . $file_ext));
//支持中文的basename
$size = filesize($original_file_path);
if (!in_array($file_ext, $this->_config['ext'])) {
return static::UPLOAD_ERR_EXT;
}
if ($size > $this->_config['maxsize']) {
return static::UPLOAD_ERR_MAXSIZE;
}
if (empty($size)) {
return static::UPLOAD_ERR_EMPTY;
}
//传文件都耗费了那么多时间,还怕md5?
$hash = md5_file($original_file_path);
$file = $this->fileModel->get_byhash($hash, $size);
if (empty($file)) {
$new_basename = $this->_get_hash_basename();
$new_hash_path = $this->get_hash_path($new_basename);
if (!$this->_save_file($original_file_path, $new_basename)) {
return static::UPLOAD_ERR_SAVE;
}
$file = AttachmentFile::create(['basename' => $new_basename, 'path' => $new_hash_path, 'hash' => $hash, 'size' => $size]);
} else {
//已经存在此文件
@unlink($original_file_path);
}
$attachment = $this->create(['afid' => $file->getKey(), 'filename' => $file_name, 'ext' => $file_ext, 'original_basename' => $original_basename, 'description' => $description, 'uid' => $uid]);
//当前Model更新
//$this->setRawAttributes($attachment->getAttributes(), true);
return $this->get($attachment->getKey());
}
开发者ID:unionbt,项目名称:hanpaimall,代码行数:37,代码来源:Attachment.php
示例18: elseif
// page refresh or a nice bar popup immediately with
// something like "This page is out-of-date", and allow the
// user to voluntarily delete their draft
//
// Delete drafts for all users for this canned response
Draft::deleteForNamespace('canned.' . $canned->getId());
} elseif (!$errors['err']) {
$errors['err'] = 'Error updating canned response. Try again!';
}
break;
case 'create':
if ($id = Canned::create($_POST, $errors)) {
$msg = 'Canned response added successfully';
$_REQUEST['a'] = null;
//Upload attachments
if ($_FILES['attachments'] && ($c = Canned::lookup($id)) && ($files = AttachmentFile::format($_FILES['attachments']))) {
$c->attachments->upload($files);
}
// Attach inline attachments from the editor
if (isset($_POST['draft_id']) && ($draft = Draft::lookup($_POST['draft_id']))) {
$c->attachments->upload($draft->getAttachmentIds($_POST['response']), true);
}
// Delete this user's drafts for new canned-responses
Draft::deleteForNamespace('canned', $thisstaff->getId());
} elseif (!$errors['err']) {
$errors['err'] = 'Unable to add canned response. Correct error(s) below and try again.';
}
break;
case 'mass_process':
if (!$_POST['ids'] || !is_array($_POST['ids']) || !count($_POST['ids'])) {
$errors['err'] = 'You must select at least one canned response';
开发者ID:ed00m,项目名称:osTicket-1.8,代码行数:31,代码来源:canned.php
示例19: removeLicense
public function removeLicense()
{
//delete all documents and associated expressions and SFX providers
$document = new Document();
foreach ($this->getDocuments() as $document) {
//delete all expressions and expression notes
$expression = new Expression();
foreach ($document->getExpressions() as $expression) {
$expressionNote = new ExpressionNote();
foreach ($expression->getExpressionNotes() as $expressionNote) {
$expressionNote->delete();
}
$expression->removeQualifiers();
$expression->delete();
}
$sfxProvider = new SFXProvider();
foreach ($document->getSFXProviders() as $sfxProvider) {
$sfxProvider->delete();
}
$signature = new Signature();
foreach ($document->getSignatures() as $signature) {
$signature->delete();
}
$document->delete();
}
//delete all attachments
$attachment = new Attachment();
foreach ($this->getAttachments() as $attachment) {
$attachmentFile = new AttachmentFile();
foreach ($attachment->getAttachmentFiles() as $attachmentFile) {
$attachmentFile->delete();
}
$attachment->delete();
}
$this->delete();
}
开发者ID:TAMULib,项目名称:CORAL-Management,代码行数:36,代码来源:License.php
示例20: run
function run($args, $options)
{
Bootstrap::connect();
osTicket::start();
switch ($args['action']) {
case 'backends':
// List configured backends
foreach (FileStorageBackend::allRegistered() as $char => $bk) {
print "{$char} -- {$bk::$desc} ({$bk})\n";
}
break;
case 'list':
// List files matching criteria
// ORM would be nice!
$files = FileModel::objects();
$this->_applyCriteria($options, $files);
foreach ($files as $f) {
printf("% 5d %s % 8d %s % 16s %s\n", $f->id, $f->bk, $f->size, $f->created, $f->type, $f->name);
if ($f->attrs) {
printf(" %s\n", $f->attrs);
}
}
break;
case 'dump':
$files = FileModel::objects();
$this->_applyCriteria($options, $files);
if ($files->count() != 1) {
$this->fail('Criteria must select exactly 1 file');
}
if (($f = AttachmentFile::lookup($files[0]->id)) && ($bk = $f->open())) {
$bk->passthru();
}
break;
case 'load':
// Load file content from STDIN
$files = FileModel::objects();
$this->_applyCriteria($options, $files);
if ($files->count() != 1) {
$this->fail('Criteria must select exactly 1 file');
}
$f = AttachmentFile::lookup($files[0]->id);
try {
if ($bk = $f->open()) {
$bk->unlink();
}
} catch (Exception $e) {
}
if ($options['to']) {
$bk = FileStorageBackend::lookup($options['to'], $f);
} else {
// Use the system default
$bk = AttachmentFile::getBackendForFile($f);
}
$type = false;
$signature = '';
$finfo = new finfo(FILEINFO_MIME_TYPE);
if ($options['file'] && $options['file'] != '-') {
if (!file_exists($options['file'])) {
$this->fail($options['file'] . ': Cannot open file');
}
if (!$bk->upload($options['file'])) {
$this->fail('Unable to upload file contents to backend');
}
$type = $finfo->file($options['file']);
list(, $signature) = AttachmentFile::_getKeyAndHash($options['file'], true);
} else {
$stream = fopen('php://stdin', 'rb');
while ($block = fread($stream, $bk->getBlockSize())) {
if (!$bk->write($block)) {
$this->fail('Unable to send file contents to backend');
}
if (!$type) {
$type = $finfo->buffer($block);
}
}
if (!$bk->flush()) {
$this->fail('Unable to commit file contents to backend');
}
}
// TODO: Update file metadata
$sql = 'UPDATE ' . FILE_TABLE . ' SET bk=' . db_input($bk->getBkChar()) . ', created=CURRENT_TIMESTAMP' . ', type=' . db_input($type) . ', signature=' . db_input($signature) . ' WHERE id=' . db_input($f->getId());
if (!db_query($sql) || db_affected_rows() != 1) {
$this->fail('Unable to update file metadata');
}
$this->stdout->write("Successfully saved contents\n");
break;
case 'migrate':
if (!$options['to']) {
$this->fail('Please specify a target backend for migration');
}
if (!FileStorageBackend::isRegistered($options['to'])) {
$this->fail('Target backend is not installed. See `backends` action');
}
$files = FileModel::objects();
$this->_applyCriteria($options, $files);
$count = 0;
foreach ($files as $m) {
$f = AttachmentFile::lookup($m->id);
if ($f->getBackend() == $options['to']) {
continue;
//.........这里部分代码省略.........
开发者ID:gizur,项目名称:osticket,代码行数:101,代码来源:file.php
注:本文中的AttachmentFile类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论