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


PHP Attachment::save方法代码示例

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


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

示例1: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $att = new Attachment();
     $att->unguard();
     $att->fill(Input::only('title', 'description', 'hash', 'hash_algorithm', 'public'));
     if (!Input::hasFile('upload')) {
         Session::flash('message', ['content' => 'Geen bestand ontvangen.', 'class' => 'danger']);
         return View::make('attachments.create', ['attachment' => $att]);
     }
     if (!Input::file('upload')->isValid()) {
         Session::flash('message', ['content' => 'Ongeldig bestand ontvangen.', 'class' => 'danger']);
         return View::make('attachments.create', ['attachment' => $att]);
     }
     $file = Input::file('upload');
     $name = $file->getClientOriginalName();
     $extension = $file->getClientOriginalExtension();
     $att->user_id = Auth::user()->id;
     $att->filename = $name;
     $att->extension = $extension;
     // We need to validate the attributes before moving the attachment into place
     if (!$att->validate()) {
         return View::make('attachments.create', ['attachment' => $att])->withErrors($att->validator());
     }
     $file->move($att->folderPath(), $att->filename);
     $att->path = $att->folderPath();
     $att->filesize = filesize($att->fullPath());
     if (in_array($att->extension, Attachment::$image_extensions)) {
         $att->type = 'Image';
     }
     $att->save();
     return Redirect::to(route('attachments.show', [$att->id]))->with('message', ['content' => 'Bestand met succes geupload!', 'class' => 'success']);
 }
开发者ID:y0sh1,项目名称:logboek,代码行数:37,代码来源:AttachmentsController.php

示例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'));
     }
 }
开发者ID:netesheng,项目名称:paperwork,代码行数:58,代码来源:ApiAttachmentsController.php

示例3: 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;
 }
开发者ID:Liongold,项目名称:paperwork,代码行数:25,代码来源:AbstractImport.php

示例4: edit

 /**
  * Show and process edit attachment form
  *
  * @param void
  * @return null
  */
 function edit()
 {
     $this->wireframe->print_button = false;
     if ($this->active_attachment->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     $parent = $this->active_attachment->getParent();
     if (!instance_of($parent, 'ProjectObject')) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     $attachment_data = $this->request->post('attachment');
     if (!is_array($attachment_data)) {
         $attachment_data = array('name' => $this->active_attachment->getName());
     }
     // if
     $this->smarty->assign('attachment_data', $attachment_data);
     if ($this->request->isSubmitted()) {
         db_begin_work();
         $old_name = $this->active_attachment->getName();
         $this->active_attachment->setName(array_var($attachment_data, 'name'));
         $save = $this->active_attachment->save();
         if ($save && !is_error($save)) {
             db_commit();
             $this->active_attachment->ready();
             if ($this->request->getFormat() == FORMAT_HTML) {
                 flash_success('File :filename has been updated', array('filename' => $old_name));
                 $this->redirectToUrl($parent->getViewUrl());
             } else {
                 $this->serveData($this->active_attachment);
             }
             // if
         } else {
             db_rollback();
             if ($this->request->getFormat() == FORMAT_HTML) {
                 flash_error('Failed to update :filename', array('filename' => $old_name));
                 $this->redirectToUrl($parent->getViewUrl());
             } else {
                 $this->serveData($save);
             }
             // if
         }
         // if
     }
     // if
 }
开发者ID:NaszvadiG,项目名称:activecollab_loc,代码行数:53,代码来源:AttachmentsController.class.php

示例5: 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>";
 }
开发者ID:Aaronwmc,项目名称:WindMill,代码行数:47,代码来源:MyUploadController.php

示例6: Attachment

     //if attachmentID is sent then this is an update
     if (isset($_POST['attachmentID']) && $_POST['attachmentID'] != "") {
         $attachment = new Attachment(new NamedArguments(array('primaryKey' => $_POST['attachmentID'])));
     } else {
         $attachment = new Attachment();
         $attachment->attachmentID = '';
     }
     if (isset($_POST['sentDate']) && $_POST['sentDate'] != "") {
         $attachment->sentDate = date("Y-m-d", strtotime($_POST['sentDate']));
     } else {
         $attachment->sentDate = "";
     }
     $attachment->attachmentText = $_POST['attachmentText'];
     $attachment->licenseID = $_POST['licenseID'];
     try {
         $attachment->save();
         echo $attachment->primaryKey;
     } catch (Exception $e) {
         echo $e->getMessage();
     }
     break;
     //adding the attachment file to the db - saves the URL to it only
 //adding the attachment file to the db - saves the URL to it only
 case 'addAttachmentFile':
     $attachmentFile = new AttachmentFile();
     $attachmentFile->attachmentID = $_GET['attachmentID'];
     $attachmentFile->attachmentURL = $_GET['attachmentURL'];
     try {
         $attachmentFile->save();
         echo $attachmentFile->primaryKey;
     } catch (Exception $e) {
开发者ID:veggiematts,项目名称:coral-licensing,代码行数:31,代码来源:ajax_processing.php

示例7: postCreate

 public function postCreate()
 {
     // $academy_id = Session::get('school_id_session');
     $academy_id = Cookie::get('school_id_session');
     if ($academy_id == NULL) {
         return Redirect::to('/task/create/step-3')->with('message', 'no-school');
     }
     $sTask = Session::get('task');
     $task = new Task();
     $task->user_id = Auth::user()->id;
     // $task->type       = Session::get('type');
     // $task->title      = Session::get('title');
     // $task->detail     = Session::get('detail');
     // $task->category_id   = Session::get('category_id');
     $task->type = $sTask['type'];
     $task->title = $sTask['title'];
     $task->detail = $sTask['detail'];
     $task->category_id = $sTask['category_id'];
     if ($sTask['type'] == 1) {
         // $task->amount     = Session::get('amount');
         $task->amount = $sTask['amount'];
         $task->totalAmount = $sTask['totalAmount'];
     } else {
         if ($sTask['type'] == 2) {
             // $task->amountStart     = Session::get('amountStart');
             // $task->amountEnd     = Session::get('amountEnd');
             if (isset($sTask['amountStart'])) {
                 $task->amountStart = $sTask['amountStart'];
                 $task->amountEnd = $sTask['amountEnd'];
             } else {
                 $task->amount = $sTask['amount'];
             }
         }
     }
     // $task->amount     = Session::get('amount');
     // $task->expiration = Session::get('expiration');
     $task->expiration = $sTask['expiration'];
     $task->state = 1;
     $task->place = $academy_id;
     $task->save();
     $credit = Auth::user()->credit;
     // dd($task->category_id);
     User::where('id', Auth::user()->id)->update(['credit' => $credit - 50]);
     if (Session::get('hire') != NULL) {
         $hired_user = User::where('id', Session::get('hire'))->first();
         $message = new Message();
         $message->from_user_id = Auth::user()->id;
         $message->to_user_id = $hired_user->id;
         $message->message = "Can you help me do this task " . "<a class='message-task-title' target='blank' href=\"/task/{$task->id}\">{$task->title}</a> ?";
         $message->save();
     }
     if (Session::has('file_name') && Session::get('file_name') != "") {
         // dd(Session::get('file_name'));
         $attachment = new Attachment();
         $attachment->file_name = Session::get('file_name');
         $attachment->task_id = $task->id;
         $attachment->save();
         $attachment->file_hash = md5($attachment->id . $attachment->created_at . $attachment->file_name . $attachment->task_id);
         $attachment->file_ext = Util::getExtension($attachment->file_name);
         $attachment->save();
         // Session::set('file_hash', $attachment->file_hash);
         if (!file_exists(public_path() . '/file/' . Auth::user()->id . '/')) {
             mkdir(public_path() . '/file/' . Auth::user()->id . '/');
         }
         if ($attachment->file_ext == "") {
             copy(public_path() . '/upload/cache/' . $attachment->file_name, public_path() . '/file/' . Auth::user()->id . '/' . $attachment->file_hash);
         } else {
             copy(public_path() . '/upload/cache/' . $attachment->file_name, public_path() . '/file/' . Auth::user()->id . '/' . $attachment->file_hash . '.' . $attachment->file_ext);
         }
     }
     // if (Session::has('images')) {
     // 	if (!file_exists(public_path() . '/file/' . Auth::user()->id . '/')) {
     // 		mkdir(public_path() . '/file/' . Auth::user()->id . '/');
     // 	}
     // 	$images = Session::get('images');
     // 	foreach ($images as $imageName) {
     // 		$oldName = public_path() . '/upload/cache/' . Auth::user()->id . '/' . $imageName;
     // 		$newName = public_path() . '/file/' . Auth::user()->id . '/' .$imageName;
     // 		rename($oldName, $newName);
     // 		$image = new Image;
     // 		$image->user_id = Auth::user()->id;
     // 		$image->task_id = $task->id;
     // 		$image->file_name = $imageName;
     // 		$image->save();
     // 	}
     // }
     Session::forget('title');
     Session::forget('detail');
     Session::forget('amount');
     Session::forget('expiration');
     Session::forget('hire');
     Session::forget('file_name');
     // return Redirect::to('task/list');
     return Redirect::to("/school/{$academy_id}");
     // return Redirect::to('/');
 }
开发者ID:bytrix,项目名称:witkey,代码行数:96,代码来源:TaskController.php

示例8: UploadFile

 public static function UploadFile($objFile)
 {
     $objAttachment = new Attachment();
     $objAttachment->creDate = MFBDateTime::Now();
     $objAttachment->save();
     $arrFileData = pathinfo($objFile['name']);
     //die(print_r($arrFileData));
     $strExtension = $arrFileData['extension'];
     $strFileName = $objAttachment->idAttachment . '.' . $strExtension;
     $strNewPath = __UPLOADS_DIR__ . '/' . $strFileName;
     move_uploaded_file($objFile["tmp_name"], $strNewPath);
     $objAttachment->fileLoc = $strFileName;
     $objAttachment->save();
     return $objAttachment;
 }
开发者ID:laiello,项目名称:schematical-open-source,代码行数:15,代码来源:FBApplicationBase.class.php

示例9: uploadAttachmentIntoDB

 /**
  * Metodo para subir un archivo al servidor y guardarlo en la base de datos
  * @param _FILE $file archivo que se esta subiendo
  * @param Attachment Entidad con toda la informacion de un archivo a guardar
  * @return JSON respuesta del proceso de carga de archivo
  */
 public static function uploadAttachmentIntoDB($file, $attachment = '')
 {
     $att = $attachment;
     if (!$att) {
         $att = new Attachment();
     }
     $f = $file;
     if ($f) {
         $att->name = $f->getClientOriginalName();
         $att->mime = $f->getMimeType();
         $att->size = $f->getSize();
         $attfile = file_get_contents($f->getRealPath());
         if ($att->encode == 'base64') {
             $attfile = base64_encode(file_get_contents($f->getRealPath()));
         }
         $att->file = $attfile;
         $att->save();
         return Response::json(array('valid' => true));
     } else {
         return Response::json(array('valid' => false, 'error' => array($f->getError(), $f->getErrorMessage())));
     }
 }
开发者ID:alexlondon07,项目名称:accounting,代码行数:28,代码来源:AttachmentController.php

示例10: save

 /**
  * Save this object into the database
  *
  * @param void
  * @return boolean
  * @throws DBQueryError
  * @throws ValidationErrors
  */
 function save()
 {
     $is_new = $this->isNew();
     $modified_fields = $this->modified_fields;
     $old_values = $this->old_values;
     if ($is_new) {
         $this->setType(get_class($this));
     }
     // if
     if ($this->isModified()) {
         $this->setVersion($this->getVersion() + 1);
         // increment object version on save...
     }
     // if
     db_begin_work();
     $save = parent::save();
     if (!$save || is_error($save)) {
         db_rollback();
         return $save;
     }
     // if
     // Log activities...
     if ($this->log_activities) {
         if ($is_new) {
             if ($this->log_creation) {
                 if (instance_of($this, 'File')) {
                     $activity_log = new NewFileActivityLog();
                 } else {
                     $activity_log = new ObjectCreatedActivityLog();
                 }
                 // if
                 $activity_log->log($this, $this->getCreatedBy());
             }
             // if
         } else {
             if ($this->log_update || $this->log_move_to_trash || $this->log_restore_from_trash) {
                 $trashed = false;
                 $restored = false;
                 if (is_array($this->modified_fields) && in_array('state', $modified_fields)) {
                     if (isset($old_values['state']) && $old_values['state'] == STATE_DELETED && $this->getState() == STATE_VISIBLE) {
                         $restored = true;
                     }
                     // if
                     if (isset($old_values['state']) && $old_values['state'] == STATE_VISIBLE && $this->getState() == STATE_DELETED) {
                         $trashed = true;
                     }
                     // if
                 }
                 // if
                 if ($trashed) {
                     if ($this->log_move_to_trash) {
                         $activity_log = new ObjectTrashedActivityLog();
                         $activity_log->log($this);
                     }
                     // if
                 } elseif ($restored) {
                     if ($this->log_restore_from_trash) {
                         $activity_log = new ObjectRestoredActivityLog();
                         $activity_log->log($this);
                     }
                     // if
                 } else {
                     if ($this->log_update) {
                         $activity_log = new ObjectUpdatedActivityLog();
                         $activity_log->log($this);
                     }
                     // if
                 }
                 // if
             }
             // if
         }
         // if
     }
     // if
     // Pending files
     if ($this->can_have_attachments && is_foreachable($this->pending_files)) {
         foreach ($this->pending_files as $pending_file) {
             $attachment = new Attachment();
             $attachment->setParent($this);
             if (isset($pending_file['created_by']) && (instance_of($pending_file['created_by'], 'User') || instance_of($pending_file['created_by'], 'AnonymousUser'))) {
                 $attachment->setCreatedBy($pending_file['created_by']);
             } else {
                 $attachment->setCreatedBy($this->getCreatedBy());
             }
             // if
             $attachment->setName($pending_file['name']);
             $attachment->setLocation(substr($pending_file['location'], strlen(UPLOAD_PATH) + 1));
             $attachment->setMimeType($pending_file['type']);
             $attachment->setSize($pending_file['size']);
             if (instance_of($this, 'File')) {
                 $attachment->setAttachmentType(ATTACHMENT_TYPE_FILE_REVISION);
//.........这里部分代码省略.........
开发者ID:NaszvadiG,项目名称:activecollab_loc,代码行数:101,代码来源:ProjectObject.class.php

示例11: Project

 /**
  * Provides logic for image picker dialog
  * 
  * @param void
  * @return null
  */
 function image_picker()
 {
     $project_id = $this->request->get('project_id');
     if ($project_id) {
         $this->active_project = Projects::findById($project_id);
     }
     // if
     if (!instance_of($this->active_project, 'Project')) {
         $this->active_project = new Project();
     }
     // if
     $image_picker_url = assemble_url('image_picker', array('project_id' => $this->active_project->getId()));
     $this->smarty->assign(array('image_picker_url' => $image_picker_url, 'disable_upload' => (bool) $this->request->get('disable_upload')));
     if ($this->request->isSubmitted()) {
         $action = $this->request->post('widget_action');
         switch ($action) {
             case 'upload':
                 // check if any file is uploaded
                 $uploaded_file = array_var($_FILES, 'image', null);
                 if (!is_array($uploaded_file)) {
                     $this->httpError(HTTP_ERR_OPERATION_FAILED, lang('You did not uploaded any file'), true, true);
                 }
                 // if
                 // we are setting base attributes
                 $attachment = new Attachment();
                 $attachment->setName($uploaded_file['name']);
                 $attachment->setMimeType($uploaded_file['type']);
                 $attachment->setSize($uploaded_file['size']);
                 $attachment->setAttachmentType(ATTACHMENT_TYPE_ATTACHMENT);
                 $attachment->setCreatedBy($this->logged_user);
                 $attachment->setCreatedOn(new DateTimeValue());
                 // check if uploaded file is image
                 if (!$attachment->isImage()) {
                     $this->httpError(HTTP_ERR_OPERATION_FAILED, lang('Uploaded file is not image'), true, true);
                 }
                 // if
                 $destination_file = get_available_uploads_filename();
                 if (!move_uploaded_file($uploaded_file['tmp_name'], $destination_file)) {
                     $this->httpError(HTTP_ERR_OPERATION_FAILED, lang('Could not copy uploaded image to work folder'), true, true);
                 }
                 // if
                 if (FIX_UPLOAD_PERMISSION !== false) {
                     @chmod($destination_file, FIX_UPLOAD_PERMISSION);
                 }
                 // if
                 $attachment->setLocation(basename($destination_file));
                 $save = $attachment->save();
                 if (!$save || is_error($save)) {
                     @unlink($destination_file);
                     $this->httpError(HTTP_ERR_OPERATION_FAILED, $save->getMessage(), true, true);
                 }
                 // if
                 echo "<img attachment_id='" . $attachment->getId() . "' src='" . $attachment->getViewUrl($this->active_project->getId()) . "' />";
                 die;
                 break;
             default:
                 break;
         }
         // switch
     }
     // if
 }
开发者ID:NaszvadiG,项目名称:activecollab_loc,代码行数:68,代码来源:WidgetsController.class.php

示例12: saveAttachment

 private function saveAttachment($file, $mailbox_id)
 {
     $attachment = new Attachment();
     $attachment->mailbox_id = $mailbox_id;
     $attachment->attachment_id = $file['file_id'];
     $attachment->original_path = $file['addresses']['from']['email'] . '/' . $file['message_id'] . '/' . $file['file_name'];
     $attachment->bytes = $file['size'];
     $attachment->mime_type = $file['type'];
     $attachment->file_sha = null;
     // Compute when downloaded
     $attachment->etag = null;
     // Compute when downloaded
     $attachment->service_created_at = date('r', $file['date_received']);
     $attachment->service_updated_at = date('r', $file['date_indexed']);
     $attachment->client_created_at = date('r', $file['date']);
     $attachment->client_updated_at = null;
     // never known
     if (!$attachment->save()) {
         return false;
     }
     Queue::push('ContextIOFileHandlerController@create', ['action' => 'create', 'attachment' => $attachment->toArray()], $this->file_queue_id);
     return true;
 }
开发者ID:andrewpurkett,项目名称:demo-dropbox-rest-service,代码行数:23,代码来源:ContextIOCrawlerController.php

示例13: actionUpload

 /**
  * undocumented function
  *
  * @return void
  * @author paranoid
  **/
 public function actionUpload()
 {
     $category_id = $_GET['category_id'];
     $user_id = $_GET['user_id'];
     if (strlen(trim($category_id)) == 0) {
         //$category_id = 30;
         $category_id = Category::model()->autoCreate();
     }
     ini_set("html_errors", "0");
     $upload_name = "Filedata";
     $path_info = pathinfo($_FILES[$upload_name]['name']);
     $file_extension = $path_info["extension"];
     $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\\[\\]\',~`-';
     // Characters allowed in the file name (in a Regular Expression format)
     //$screen_name = preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
     $screen_name = basename($_FILES[$upload_name]['name']);
     $time = time();
     $file_name = $time . '.' . $file_extension;
     $put_file_path = API::upload_prefix_dir();
     $put_file_to_dir = ATMS_SAVE_DIR . $put_file_path;
     if (!@move_uploaded_file($_FILES[$upload_name]["tmp_name"], $put_file_to_dir . $file_name)) {
         echo 'fuck';
         exit(0);
     }
     $model = new Attachment();
     $is_image = false;
     $w = 0;
     $h = 0;
     if (in_array(strtolower($file_extension), API::$IMAGE_EXTENSION)) {
         $image = Yii::app()->image->load($put_file_to_dir . $file_name);
         $w = $image->width;
         $h = $image->height;
         $is_image = true;
     }
     $ati = array('screen_name' => $screen_name, 'path' => $put_file_path . $time, 'w' => $w, 'h' => $h, 'c_time' => Time::now(), 'extension' => $file_extension, 'category_id' => $category_id, 'user_id' => $user_id);
     $model->attributes = $ati;
     if ($model->save()) {
         if ($is_image) {
             $model->tips = str_pad($w, 4, "_", STR_PAD_LEFT) . '*' . str_pad($h, 4, "_", STR_PAD_RIGHT) . ',';
             foreach (API::$ATT_IMG_AUTO_SIZE as $k => $v) {
                 $file_path = $put_file_to_dir . $time . '_' . $v . '.' . $file_extension;
                 list($dw, $dh) = explode('_', $v);
                 if ($w > $dw && $h > $dh) {
                     if ($h / $w > $dh / $dw) {
                         if ($k == 'thumb') {
                             $image->resize($dw * 1.2, $dh * 1.2, Image::WIDTH)->crop($dw, $dh, '20', 'center');
                         } else {
                             $image->resize($dw, $dh, Image::WIDTH);
                         }
                     } else {
                         if ($k == 'thumb') {
                             $image->resize($dw * 1.2, $dh * 1.2, Image::HEIGHT)->crop($dw, $dh, '20', 'center');
                         } else {
                             $image->resize($dw, $dh, Image::HEIGHT);
                         }
                     }
                     $model->tips .= str_pad($dw, 4, "_", STR_PAD_LEFT) . '*' . str_pad($dh, 4, "_", STR_PAD_RIGHT) . ',';
                 }
                 $image->save($file_path);
             }
             $model->save();
             rename($put_file_to_dir . $file_name, $put_file_to_dir . $time . '_' . $w . '_' . $h . '.' . $file_extension);
             /*
             	      $file_path_l = $put_file_to_dir.$time.'_800_600'.'.'.$file_extension;
             $file_path_t = $put_file_to_dir.$time.'_160_120'.'.'.$file_extension;
             $file_path_g = $put_file_to_dir.$time.'_48_48'.'.'.$file_extension;        
             
             if( $w >800 && $h>600){
               $image->resize(800, 600);
             }
             $image->save($file_path_l);          	            
             
             if( $w >160 && $h>120){
               $image->resize(160, 120);
             }
             //,Image::NONE);        
             $image->save($file_path_t);
             
             $image->resize(48, 48);
             $image->save($file_path_g);
             
             $model->tips  = str_pad($w, 4, "_", STR_PAD_LEFT).'*'. str_pad($h,4,"_", STR_PAD_RIGHT).',';
             $model->tips .= '_800*600_,';
             $model->tips .= '_160*120_,';
             $model->tips .= '__48*48__,';
             $model->save();
             rename($put_file_to_dir.$file_name, $put_file_to_dir.$time.'_'.$w.'_'.$h.'.'.$file_extension );
             */
         }
     }
 }
开发者ID:paranoidxc,项目名称:iwebhost,代码行数:97,代码来源:AttachmentController.php

示例14: returnUrl

 public function returnUrl()
 {
     /* * 
      * 功能:支付宝页面跳转同步通知页面
      * 版本:3.3
      * 日期:2012-07-23
      * 说明:
      * 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
      * 该代码仅供学习和研究支付宝接口使用,只是提供一个参考。
      *************************页面功能说明*************************
      * 该页面可在本机电脑测试
      * 可放入HTML等美化页面的代码、商户业务逻辑程序代码
      * 该页面可以使用PHP开发工具调试,也可以使用写文本函数logResult,该函数已被默认关闭,见alipay_notify_class.php中的函数verifyReturn
      */
     // require_once("alipay.config.php");
     // require_once("lib/alipay_notify.class.php");
     require_once public_path() . "/alipay/alipay.config.php";
     require_once public_path() . "/alipay/lib/alipay_notify.class.php";
     //计算得出通知验证结果
     $alipayNotify = new AlipayNotify($alipay_config);
     $verify_result = $alipayNotify->verifyReturn();
     if ($verify_result) {
         //验证成功
         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
         //请在这里加上商户的业务逻辑程序代码
         //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
         //获取支付宝的通知返回参数,可参考技术文档中页面跳转同步通知参数列表
         //商户订单号
         $out_trade_no = $_GET['out_trade_no'];
         //支付宝交易号
         $trade_no = $_GET['trade_no'];
         //交易状态
         $trade_status = $_GET['trade_status'];
         if ($_GET['trade_status'] == 'TRADE_FINISHED' || $_GET['trade_status'] == 'TRADE_SUCCESS') {
             //判断该笔订单是否在商户网站中已经做过处理
             //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
             //如果有做过处理,不执行商户的业务程序
             // POST TASK
             $academy_id = Cookie::get('school_id_session');
             $sTask = Session::get('task');
             if ($academy_id == NULL) {
                 return Redirect::to('/task/create/step-3')->with('message', 'no-school');
             }
             $task = new Task();
             $task->trade_no = $out_trade_no;
             $task->user_id = Auth::user()->id;
             // $task->type       = Session::get('type');
             // $task->title      = Session::get('title');
             // $task->detail     = Session::get('detail');
             // $task->category_id   = Session::get('category_id');
             $task->type = $sTask['type'];
             $task->title = $sTask['title'];
             $task->detail = $sTask['detail'];
             $task->category_id = $sTask['category_id'];
             if ($sTask['type'] == 1) {
                 // $task->amount     = Session::get('amount');
                 $task->amount = $sTask['amount'];
             } else {
                 if ($sTask['type'] == 2) {
                     // $task->amountStart     = Session::get('amountStart');
                     // $task->amountEnd     = Session::get('amountEnd');
                     $task->amountStart = $sTask['amountStart'];
                     $task->amountEnd = $sTask['amountEnd'];
                 }
             }
             // $task->amount     = Session::get('amount');
             // $task->expiration = Session::get('expiration');
             $task->expiration = $sTask['expiration'];
             $task->state = 1;
             $task->place = $academy_id;
             $task->save();
             $credit = Auth::user()->credit;
             // dd($task->category_id);
             User::where('id', Auth::user()->id)->update(['credit' => $credit - 50]);
             if ($sTask['hire'] != NULL) {
                 // $hired_user = User::where('id', Session::get('hire'))->first();
                 $hired_user = User::where('id', $sTask['hire'])->first();
                 $message = new Message();
                 $message->from_user_id = Auth::user()->id;
                 $message->to_user_id = $hired_user->id;
                 $message->message = "Can you help me do this task " . "<a class='message-task-title' target='blank' href=\"/task/{$task->id}\">{$task->title}</a> ?";
                 $message->save();
             }
             // if (Session::has('file_name') && Session::get('file_name') != "") {
             if ($sTask['file_name'] != "") {
                 // dd(Session::get('file_name'));
                 $attachment = new Attachment();
                 // $attachment->file_name = Session::get('file_name');
                 $attachment->file_name = $sTask['file_name'];
                 $attachment->task_id = $task->id;
                 $attachment->save();
                 $attachment->file_hash = md5($attachment->id . $attachment->created_at . $attachment->file_name . $attachment->task_id);
                 $attachment->file_ext = Util::getExtension($attachment->file_name);
                 $attachment->save();
                 // Session::set('file_hash', $attachment->file_hash);
                 if (!file_exists(public_path() . '/file/' . Auth::user()->id . '/')) {
                     mkdir(public_path() . '/file/' . Auth::user()->id . '/');
                 }
                 if ($attachment->file_ext == "") {
                     copy(public_path() . '/upload/cache/' . $attachment->file_name, public_path() . '/file/' . Auth::user()->id . '/' . $attachment->file_hash);
//.........这里部分代码省略.........
开发者ID:bytrix,项目名称:witkey,代码行数:101,代码来源:AlipayController.php

示例15: update

 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(article $article, Request $request)
 {
     $article->user_id = Auth::user()->id;
     $article->title = $request->title;
     $article->body = $request->body;
     $article->attach = $request->image;
     $article->edit_version = $article->edit_version + 1;
     if ($article->save()) {
         $files = $request->file('attach');
         foreach ($files as $index => $file) {
             if ($file->isValid()) {
                 if ($file->move($this->upload_dir . $article->id . '/', $article->edit_version . $file->getClientOriginalName())) {
                     $attachment = new Attachment();
                     $attachment->article_id = $article->id;
                     $attachment->name = $article->edit_version . $file->getClientOriginalName();
                     $attachment->description = "Dis";
                     $attachment->save();
                     if ($index === 0) {
                         $article->attach = $attachment->name;
                         $article->save();
                     }
                 }
             }
         }
         $request->session()->flash('edited', 'Task was successful!');
     }
     return redirect('articles/' . $article->id . '/edit/');
 }
开发者ID:jryan2209,项目名称:chloee,代码行数:35,代码来源:articleController.php


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