当前位置: 首页>>代码示例>>PHP>>正文


PHP Attachment::find方法代码示例

本文整理汇总了PHP中Attachment::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Attachment::find方法的具体用法?PHP Attachment::find怎么用?PHP Attachment::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Attachment的用法示例。


在下文中一共展示了Attachment::find方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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);
 }
开发者ID:benallfree,项目名称:laravel-stapler-images,代码行数:35,代码来源:AttachmentTrait.php

示例2: loadAttachment

 private function loadAttachment($attachmentId)
 {
     $attachment = Attachment::find($attachmentId);
     if (is_null($attachment)) {
         throw new Exception('Document parsing job #' . $this->job->getJobId() . ' contains an invalid document_id. Aborting.');
     }
     return $attachment;
 }
开发者ID:jinchen891021,项目名称:paperwork,代码行数:8,代码来源:DocumentParserWorker.php

示例3: __uninstall

 static function __uninstall($confirm)
 {
     if ($confirm) {
         foreach (Attachment::find() as $attachment) {
             @unlink(uploaded($attachment->path, true));
         }
         SQL::current()->query("DROP TABLE __attachments");
     }
 }
开发者ID:vito,项目名称:chyrp-site,代码行数:9,代码来源:attachments.php

示例4: insertAttachment

 public function insertAttachment($attachmentIds)
 {
     if (!is_array($attachmentIds)) {
         return false;
     }
     $attachmentIds = array_unique($attachmentIds);
     foreach ($attachmentIds as $v) {
         $model = Attachment::find()->andWhere(['cid' => $v])->one();
         if (!$model || $model->parent != 0) {
             continue;
         }
         $model->parent = $this->cid;
         $model->update(false);
     }
     return true;
 }
开发者ID:Penton,项目名称:MoBlog,代码行数:16,代码来源:AttachmentOperationTrait.php

示例5: getAttachment

 /**
  * 
  * @param string $action view|download|base64
  * <p><b>view: </b>presenta el archivo en el navegador</p>
  * <p><b>download: </b>descarga el archivo</p>
  * <p><b>base64: </b>envia el archivo en base64</p>
  * @param int $id
  * @param string $key MD5($id . MD5('lorapp')). Evita que al cambiar $id se muestre otro archivo
  * @return file
  */
 public static function getAttachment($action, $id, $key = null)
 {
     $data = '';
     if ($key == MD5($id . MD5('lorapp'))) {
         $file = Attachment::find($id);
         $name = $file->name;
         $mime = $file->mime;
         $size = $file->size;
         $encode = $file->encode;
         $data = $file->file;
         if ($encode == 'base64') {
             $data = base64_decode($file->file);
         }
         $upload_path = $file->upload_path;
         if ($upload_path) {
             $upload_path = $file_path = public_path() . DIRECTORY_SEPARATOR . $file->upload_path . DIRECTORY_SEPARATOR . $file->name;
             $data = file_get_contents($upload_path);
         }
         if ($action == 'view') {
             return Response::make($data, 200, array('Content-type' => $mime, 'Content-length' => $size));
         } else {
             if ($action == 'download') {
                 return Response::make($data, 200, array('Content-type' => $mime, 'Content-length' => $size, 'Content-Disposition' => 'attachment; filename=' . $name));
             } else {
                 if ($action == 'base64') {
                     return 'data:' . $file->mime . ';base64,' . $data;
                 }
             }
         }
     } else {
         if ($action == 'name') {
             $file = Attachment::where('name', '=', $id)->first();
             $name = $file->name;
             $mime = $file->mime;
             $size = $file->size;
             $encode = $file->encode;
             $data = $file->file;
             if ($encode == 'base64') {
                 $data = base64_decode($file->file);
             }
             $data = $file->file;
             return Response::make($data, 200, array('Content-type' => $mime, 'Content-length' => $size));
         } else {
             return Response::make($data, 200, array('Content-type' => '', 'Content-length' => 0));
         }
     }
 }
开发者ID:alexlondon07,项目名称:accounting,代码行数:57,代码来源:AttachmentController.php

示例6: localize

 public function localize($file_id)
 {
     $contentClient = new \Guzzle\Service\Client('http://' . Config::get('app.content_host') . '/');
     $attachment = Attachment::find($file_id);
     $mailbox = Mailbox::find($attachment->mailbox_id);
     $tmpfname = tempnam(sys_get_temp_dir(), $file_id);
     $response = $this->contextIO->getFileContent($mailbox->mailbox_id, ['file_id' => $attachment->attachment_id], $tmpfname);
     if (!$response) {
         return ['success' => false, 'error_message' => 'Failed to retrieve context.io file contents'];
     }
     $sha1 = sha1_file($tmpfname);
     if (strrpos(basename($attachment->original_path), '.')) {
         $extension = substr(basename($attachment->original_path), strrpos(basename($attachment->original_path), '.'));
     } else {
         $extension = ".extensionless";
     }
     $save_path = 'dropbox/' . $sha1 . $extension;
     // check the byte size of the cached file if it exists on the content server
     $request = $contentClient->head($save_path);
     try {
         $response = $request->send();
         $contentLength = $response->getContentLength();
     } catch (Guzzle\Http\Exception\BadResponseException $e) {
         $clientResponseException = $e->getResponse();
         $statusCode = $clientResponseException->getStatusCode();
         if ($statusCode !== 404) {
             return ['success' => false, 'error_message' => 'HEAD request from content server path ' . $save_path . ' raised http exception ' . $statusCode . "\n" . print_r($clientResponseException, true)];
         }
         $contentLength = false;
     }
     // Raise an exception if we are about to localize this file in place of another file with the same content SHA
     if ($contentLength && $contentLength > 0 && $contentLength != filesize($tmpfname)) {
         return ['success' => false, 'error_message' => "File exists on content server with same SHA but different byte count!"];
     }
     // Upload the file if it does not already exist on the content server
     if (!$contentLength) {
         $request = $contentClient->put($save_path);
         $request->getCurlOptions()->set(CURLOPT_SSL_VERIFYHOST, false);
         // for testing ONLY!
         $request->getCurlOptions()->set(CURLOPT_SSL_VERIFYPEER, false);
         // for testing ONLY!
         // TODO: Determine which approach is best of these two:
         // Having a second pointer on same file, while first pointer is still open
         // (Temp files are deleted as soon as fclose called)
         $request->setBody(fopen($tmpfname, 'r'));
         // Or should we use....
         // rewind($fd);
         // $request->setBody($fd);
         // I'm not sure if guzzle would support that,
         // nor if w+ mode supports rewind
         // (Will it read from start without erasing after a rewind in w+?)
         $response = $request->send();
     }
     // Update the database with the file size information
     $attachment->file_sha = $sha1;
     $attachment->etag = sha1($sha1 . $attachment->bytes . $attachment->service_updated_at . $attachment->client_updated_at);
     $attachment->save();
     // TODO: Error handling
     // TODO: Process abstraction from controller to classes
     return ['success' => true, 'local_url' => 'http://' . Config::get('app.content_host') . '/' . $save_path];
 }
开发者ID:andrewpurkett,项目名称:demo-dropbox-rest-service,代码行数:61,代码来源:ContextIOCrawlerController.php


注:本文中的Attachment::find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。