本文整理汇总了PHP中Attachment类的典型用法代码示例。如果您正苦于以下问题:PHP Attachment类的具体用法?PHP Attachment怎么用?PHP Attachment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Attachment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: recordInbound
function recordInbound()
{
$strJson = file_get_contents("php://input");
try {
$arrResponse = Convert::json2array($strJson);
if ($savedMessage = PostmarkMessage::get()->filter('MessageID', $arrResponse['MessageID'])->first()) {
return;
}
$hash = $arrResponse['ToFull'][0]['MailboxHash'];
$hashParts = explode('+', $hash);
$lastMessage = PostmarkMessage::get()->filter(array('UserHash' => $hashParts[0], 'MessageHash' => $hashParts[1]))->first();
$fromCustomer = PostmarkHelper::find_or_make_client($arrResponse['From']);
$inboundSignature = null;
if ($lastMessage) {
$inboundSignature = $lastMessage->From();
} else {
if (!$lastMessage && isset($arrResponse['To'])) {
$inboundSignature = PostmarkSignature::get()->filter('Email', $arrResponse['To'])->first();
}
}
if (!$inboundSignature) {
$inboundSignature = PostmarkSignature::get()->filter('IsDefault', 1)->first();
}
$message = new PostmarkMessage(array('Subject' => $arrResponse['Subject'], 'Message' => $arrResponse['HtmlBody'], 'ToID' => 0, 'MessageID' => $arrResponse['MessageID'], 'InReplyToID' => $lastMessage ? $lastMessage->ID : 0, 'FromCustomerID' => $fromCustomer ? $fromCustomer->ID : 0, 'InboundToID' => $inboundSignature ? $inboundSignature->ID : 0));
$message->write();
if (isset($arrResponse['Attachments']) && count($arrResponse['Attachments'])) {
foreach ($arrResponse['Attachments'] as $attachment) {
$attachmentObject = new Attachment(array('Content' => $attachment['Content'], 'FileName' => $attachment['Name'], 'ContentType' => $attachment['ContentType'], 'Length' => $attachment['ContentLength'], 'ContentID' => $attachment['ContentID'], 'PostmarkMessageID' => $message->ID));
$attachmentObject->write();
}
}
} catch (Exception $e) {
}
return 'OK';
}
示例2: store
public function store($notebookId, $noteId, $versionId)
{
$note = self::getNote($notebookId, $noteId, $versionId);
if ($note->pivot->umask < PaperworkHelpers::UMASK_READWRITE) {
return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_ERROR, array('message' => 'Permission Error'));
}
if (Input::hasFile('file') && Input::file('file')->isValid() || Input::json() != null && Input::json() != "") {
$fileUpload = null;
$newAttachment = null;
if (Input::hasFile('file')) {
$fileUpload = Input::file('file');
$newAttachment = new Attachment(array('filename' => $fileUpload->getClientOriginalName(), 'fileextension' => $fileUpload->getClientOriginalExtension(), 'mimetype' => $fileUpload->getMimeType(), 'filesize' => $fileUpload->getSize()));
} else {
$fileUploadJson = Input::json();
$fileUpload = base64_decode($fileUploadJson->get('file'));
$newAttachment = new Attachment(array('filename' => $fileUploadJson->get('clientOriginalName'), 'fileextension' => $fileUploadJson->get('clientOriginalExtension'), 'mimetype' => $fileUploadJson->get('mimeType'), 'filesize' => count($fileUpload)));
}
$newAttachment->save();
// Move file to (default) /app/storage/attachments/$newAttachment->id/$newAttachment->filename
$destinationFolder = Config::get('paperwork.attachmentsDirectory') . '/' . $newAttachment->id;
if (!File::makeDirectory($destinationFolder, 0700)) {
$newAttachment->delete();
return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_ERROR, array('message' => 'Internal Error'));
}
// Get Version with versionId
//$note = self::getNote($notebookId, $noteId, $versionId);
$tmp = $note ? $note->version()->first() : null;
$version = null;
if (is_null($tmp)) {
$newAttachment->delete();
File::deleteDirectory($destinationFolder);
return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_NOTFOUND, array('message' => 'version->first'));
}
while (!is_null($tmp)) {
if ($tmp->id == $versionId || $versionId == 0) {
$version = $tmp;
break;
}
$tmp = $tmp->previous()->first();
}
if (is_null($version)) {
$newAttachment->delete();
File::deleteDirectory($destinationFolder);
return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_NOTFOUND, array('message' => 'version'));
}
if (Input::hasFile('file')) {
$fileUpload->move($destinationFolder, $fileUpload->getClientOriginalName());
} else {
file_put_contents($destinationFolder . '/' . $fileUploadJson->get('clientOriginalName'), $fileUpload);
}
$version->attachments()->attach($newAttachment);
// Let's push that parsing job, which analyzes the document, converts it if needed and parses the crap out of it.
Queue::push('DocumentParserWorker', array('user_id' => Auth::user()->id, 'document_id' => $newAttachment->id));
return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_SUCCESS, $newAttachment);
} else {
return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_ERROR, array('message' => 'Invalid input'));
}
}
示例3: deleteSelection
public function deleteSelection($attachments)
{
$return = 1;
foreach ($attachments as $id_attachment) {
$attachment = new Attachment((int) $id_attachment);
$return &= $attachment->delete();
}
return $return;
}
示例4: createTables
/**
* We need a table for the attachments if it doesnt exist TBL_ATTACHMENT
*/
function createTables()
{
$tables = array();
if ($this->verifyTable('TBL_ATTACHMENT')) {
$obj = new Attachment($this->db);
$tables[] = $obj->generateCreateTables();
}
$tables = $this->addLinkTables($tables);
$this->execute($tables);
}
示例5: LoadAll
public static function LoadAll()
{
$sql = sprintf("SELECT * FROM %s;", self::TABLE_NAME);
$result = LoadDriver::query($sql);
$coll = new BaseEntityCollection();
while ($data = mysql_fetch_assoc($result)) {
$tObj = new Attachment();
$tObj->materilize($data);
$coll->addItem($tObj);
}
return $coll;
}
示例6: getData
/**
* Get message data
*
* @return array
*/
public function getData()
{
$res = ['recipient' => ['id' => $this->recipient]];
$attachment = new Attachment(Attachment::TYPE_AUDIO);
if (strpos($this->text, 'http://') === 0 || strpos($this->text, 'https://') === 0) {
$attachment->setPayload(array('url' => $this->text));
} else {
$attachment->setFileData($this->getCurlValue($this->text, mime_content_type($this->text), basename($this->text)));
}
$res['message'] = $attachment->getData();
return $res;
}
示例7: configure
public function configure()
{
if ($category = $this->getObject()->getCategory()) {
$this->embedForm('category', new CategoryForm($this->getObject()->getCategory()));
}
if ($this->getOption('with_attachment')) {
$attachment = new Attachment();
$attachment->setArticle($this->object);
$attachmentForm = new AttachmentForm($attachment);
unset($attachmentForm['article_id']);
$this->embedForm('attachment', $attachmentForm);
}
}
示例8: processRow
/**
* Process db row
* @param array $row
* @return array
*/
public function processRow(array $row)
{
global $ADMIN;
// edit link
$row['file_name'] = sprintf('<a href="/%s/media-archive/edit-attachment.php?f_attachment_id=%d">%s</a>', $ADMIN, $row['id'], $row['file_name']);
// human readable size
$row['size_in_bytes'] = parent::FormatFileSize($row['size_in_bytes']);
// yes/no disposition
$row['content_disposition'] = empty($row['content_disposition']) ? getGS('Yes') : getGS('No');
// get in use info
$object = new Attachment($row['id']);
$row['InUse'] = (int) $object->inUse();
return array_values($row);
}
示例9: main_delete_attachment
public function main_delete_attachment()
{
if (!isset($_GET['id'])) {
error(__("No ID Specified"), __("An ID is required to delete an attachment.", "attachments"));
}
$attachment = new Attachment($_GET['id']);
if ($attachment->no_results) {
error(__("Error"), __("Invalid attachment ID specified.", "attachments"));
}
if (!$attachment->deletable()) {
show_403(__("Access Denied"), __("You do not have sufficient privileges to delete this attachment.", "attachments"));
}
Attachment::delete($attachment->id);
Flash::notice(__("Attachment deleted.", "attachments"), $_SESSION['redirect_to']);
}
示例10: actionPickAtt
public function actionPickAtt()
{
$return_id = $_GET['return_id'];
$rtype = $_GET['rtype'];
$criteria = new CDbCriteria();
if (isset($_GET['keyword'])) {
$screen_name = trim($_GET['keyword']);
$criteria->condition = 'screen_name like :screen_name';
$criteria->params = array(':screen_name' => "%{$screen_name}%");
$partial_tpl = '_att';
//$atts = Attachment::model()->findAll($criteria);
//$this->renderPartial('_att',array('return_id' => $return_id,'atts' => $atts,'rtype' => $rtype ),false,true);
} else {
$partial_tpl = 'pickatt';
//$atts = Attachment::model()->findAll();
//$this->renderPartial('pickatt',array('return_id' => $return_id,'atts' => $atts ,'rtype' => $rtype ),false,true);
}
$item_count = Attachment::model()->count($criteria);
$page_size = 10;
$pages = new CPagination($item_count);
$pages->setPageSize($page_size);
$pagination = new CLinkPager();
$pagination->cssFile = false;
$pagination->setPages($pages);
$pagination->init();
$criteria->limit = $page_size;
$criteria->offset = $pages->offset;
$select_pagination = new CListPager();
$select_pagination->htmlOptions['onchange'] = "";
$select_pagination->setPages($pages);
$select_pagination->init();
$atts = Attachment::model()->findAll($criteria);
$this->renderPartial($partial_tpl, array('return_id' => $return_id, 'atts' => $atts, 'rtype' => $rtype, 'pagination' => $pagination, 'select_pagination' => $select_pagination), false, true);
}
示例11: handleTreeEditPost
private function handleTreeEditPost()
{
$request = Request::getInstance();
$values = $request->getRequest(Request::POST);
try {
if (!$request->exists('tree_id')) {
throw new Exception('Node ontbreekt.');
}
if (!$request->exists('tag')) {
throw new Exception('Tag ontbreekt.');
}
$tree_id = intval($request->getValue('tree_id'));
$tag = $request->getValue('tag');
$key = array('tree_id' => $tree_id, 'tag' => $tag);
if ($this->exists($key)) {
$this->update($key, $values);
} else {
$this->insert($values);
}
$treeRef = new AttachmentTreeRef();
$treeRef->delete($key);
foreach ($values['ref_tree_id'] as $ref_tree_id) {
$key['ref_tree_id'] = $ref_tree_id;
$treeRef->insert($key);
}
viewManager::getInstance()->setType(ViewManager::ADMIN_OVERVIEW);
$this->plugin->getReferer()->handleHttpGetRequest();
} catch (Exception $e) {
$template = new TemplateEngine();
$template->setVariable('errorMessage', $e->getMessage(), false);
$this->handleTreeEditGet(false);
}
}
示例12: createAttachment
/**
* Create Attachment instance and move file to attachmentsDirectory
*
* @param $data
* @param $fileName
* @param string $mime
* @return \Attachment
* @throws \Exception
*/
protected function createAttachment($data, $fileName, $mime = '')
{
if (empty($mime)) {
$f = finfo_open();
$mime = finfo_buffer($f, $data, FILEINFO_MIME_TYPE);
}
$newAttachment = new \Attachment(array('filename' => $fileName, 'fileextension' => pathinfo($fileName, PATHINFO_EXTENSION), 'mimetype' => $mime, 'filesize' => strlen($data)));
$newAttachment->save();
$destinationFolder = \Config::get('paperwork.attachmentsDirectory') . '/' . $newAttachment->id;
if (!\File::makeDirectory($destinationFolder, 0700)) {
$newAttachment->delete();
throw new \Exception('Error creating directory');
}
file_put_contents($destinationFolder . '/' . $fileName, $data);
return $newAttachment;
}
示例13: mutateAttribute
public function mutateAttribute($key, $value)
{
preg_match('/(.*)_(image|file)(_la)?$/', $key, $matches);
if (count($matches) > 0) {
list($match_data, $field_name_prefix, $field_type) = $matches;
$la_mode = count($matches) == 4;
$field_name = "{$field_name_prefix}_{$field_type}_id";
if (!$this->{$field_name}) {
return null;
}
switch ($field_type) {
case 'image':
$obj = Image::find($this->{$field_name});
break;
case 'file':
$obj = Attachment::find($this->{$field_name});
break;
default:
throw new \Exception("Unrecognized attachment type {$field_type}");
}
if (!$obj) {
return null;
}
if ($la_mode) {
// Recover image if missing from Laravel Admin
$la_fpath = config('laravel-stapler.images.la_path') . "/{$obj->att_file_name}";
if (!file_exists($la_fpath)) {
copy($obj->path('admin'), $la_fpath);
}
return $obj->att_file_name;
}
return $obj->att;
}
return parent::mutateAttribute($key, $value);
}
示例14: run
public function run()
{
$faker = Faker::create();
foreach (range(1, 10) as $index) {
Attachment::create([]);
}
}
示例15: actionRepairUpload
public function actionRepairUpload()
{
$index = $this->request->getParam("selectedIndex");
$pre_id = $this->request->getParam("upload_save_to_db_id");
$inputFileName = "repair_attached_file" . $index;
$attach = CUploadedFile::getInstanceByName($inputFileName);
$retValue = "";
if ($attach == null) {
$retValue = "提示:不能上传空文件。";
} else {
if ($attach->size > 2000000) {
$retValue = "提示:文件大小不能超过2M。";
} else {
$retValue = '恭喜,上传成功!';
if ($pre_id == 0) {
$f = file_get_contents($attach->tempName);
$a = new Attachment();
$a->ref_type = "failParts";
$a->data = $f;
$a->file_path = $attach->name;
$a->save();
$cur_id = $a->id;
} else {
$trans = Yii::app()->db->beginTransaction();
try {
$f = file_get_contents($attach->tempName);
$a = new Attachment();
$a->ref_type = "failParts";
$a->data = $f;
$a->file_path = $attach->name;
$a->save();
$cur_id = $a->id;
$pre = Attachment::model()->findByPk($pre_id);
$pre->delete();
$trans->commit();
} catch (Exception $e) {
$retValue = $e->getMessage();
$cur_id = 0;
$trans->rollback();
}
}
echo "<script type='text/javascript'>window.top.window.successUpload('{$retValue}',{$cur_id},{$index})</script>";
exit;
}
}
echo "<script type='text/javascript'>window.top.window.stopUpload('{$retValue}',{$index})</script>";
}