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


PHP FileModel::save方法代码示例

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


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

示例1: makeByUploadedFile

 /**
  * Given an instance of a CUploadedFile, make a FileModel, save it, and return it.
  * If the file is empty, an exception is thrown otherwise the fileModel is returned.
  * @param object $uploadedFile CUploadedFile
  */
 public static function makeByUploadedFile($uploadedFile)
 {
     assert('$uploadedFile instanceof CUploadedFile');
     $fileContent = new FileContent();
     $fileContent->content = file_get_contents($uploadedFile->getTempName());
     $file = new FileModel();
     $file->fileContent = $fileContent;
     $file->name = $uploadedFile->getName();
     $file->type = $uploadedFile->getType();
     $file->size = $uploadedFile->getSize();
     if (!$file->save()) {
         throw new FailedFileUploadException(Zurmo::t('ZurmoModule', 'File failed to upload. The file is empty.'));
     }
     return $file;
 }
开发者ID:maruthisivaprasad,项目名称:zurmo,代码行数:20,代码来源:FileModelUtil.php

示例2: createFileModel

 public static function createFileModel($fileName = 'testNote.txt')
 {
     $pathToFiles = Yii::getPathOfAlias('application.modules.zurmo.tests.unit.files');
     $filePath = $pathToFiles . DIRECTORY_SEPARATOR . $fileName;
     $contents = file_get_contents($pathToFiles . DIRECTORY_SEPARATOR . $fileName);
     $fileContent = new FileContent();
     $fileContent->content = $contents;
     $file = new FileModel();
     $file->fileContent = $fileContent;
     $file->name = $fileName;
     $file->type = ZurmoFileHelper::getMimeType($pathToFiles . DIRECTORY_SEPARATOR . $fileName);
     $file->size = filesize($filePath);
     $saved = $file->save();
     assert('$saved');
     // Not Coding Standard
     return $file;
 }
开发者ID:RamaKavanan,项目名称:InitialVersion,代码行数:17,代码来源:ZurmoTestHelper.php

示例3: populateWithFiles

 protected function populateWithFiles($model, $numberOfFilesToAttach, $pathToFiles)
 {
     assert('$model instanceof EmailTemplate  || $model instanceof Autoresponder || $model instanceof Campaign');
     for ($i = 0; $i < $numberOfFilesToAttach; $i++) {
         $fileName = $this->files[array_rand($this->files)];
         $filePath = $pathToFiles . DIRECTORY_SEPARATOR . $fileName;
         $contents = file_get_contents($pathToFiles . DIRECTORY_SEPARATOR . $fileName);
         $fileContent = new FileContent();
         $fileContent->content = $contents;
         $file = new FileModel();
         $file->fileContent = $fileContent;
         $file->name = $fileName;
         $file->type = ZurmoFileHelper::getMimeType($pathToFiles . DIRECTORY_SEPARATOR . $fileName);
         $file->size = filesize($filePath);
         $saved = $file->save();
         if (!$saved) {
             throw new FailedToSaveModelException();
         }
         $model->files->add($file);
     }
 }
开发者ID:maruthisivaprasad,项目名称:zurmo,代码行数:21,代码来源:MarketingDemoDataMaker.php

示例4: postUpload

 function postUpload()
 {
     $file = Input::file('file');
     if ($file) {
         $destinationPath = public_path() . '/uploads/';
         $dir = date('Y-m-d');
         if (!file_exists(public_path() . '/uploads/' . $dir)) {
             mkdir(public_path() . "/uploads/" . $dir, 0777);
         }
         $destinationPath = public_path() . '/uploads/' . $dir . '/';
         $filename = $file->getClientOriginalName();
         $upload_success = Input::file('file')->move($destinationPath, $filename);
         $file = new FileModel();
         $file->filename = $dir . '/' . $filename;
         $file->uploaded_at = date('Y:m:d h:i:s');
         $file->save();
         if ($upload_success) {
             // resizing an uploaded file
             Image::make($destinationPath . $filename)->resize(100, 100)->save($destinationPath . "100x100_" . $filename);
             return Response::json('success', 200);
         } else {
             return Response::json('error', 400);
         }
     }
 }
开发者ID:alphatelradius,项目名称:histogram-tool,代码行数:25,代码来源:FilesController.php

示例5: saveLogoFile

 public static function saveLogoFile($fileName, $filePath, $fileModelIdentifier)
 {
     if (ZurmoConfigurationUtil::getByModuleName('ZurmoModule', $fileModelIdentifier) !== null) {
         $fileModelId = ZurmoConfigurationUtil::getByModuleName('ZurmoModule', $fileModelIdentifier);
         $file = FileModel::getById($fileModelId);
         $contents = file_get_contents($filePath);
         $file->fileContent->content = $contents;
         $file->name = $fileName;
         $file->type = ZurmoFileHelper::getMimeType($filePath);
         $file->size = filesize($filePath);
         $file->save();
         return $file->id;
     } else {
         $contents = file_get_contents($filePath);
         $fileContent = new FileContent();
         $fileContent->content = $contents;
         $file = new FileModel();
         $file->fileContent = $fileContent;
         $file->name = $fileName;
         $file->type = ZurmoFileHelper::getMimeType($filePath);
         $file->size = filesize($filePath);
         $file->save();
         return $file->id;
     }
 }
开发者ID:KulturedKitsch,项目名称:kulturedkitsch.info,代码行数:25,代码来源:ZurmoUserInterfaceConfigurationFormAdapter.php

示例6: testSavingFileContentWhenNotModified

 public function testSavingFileContentWhenNotModified()
 {
     $fileContent = new FileContent();
     $fileContent->content = 'testContent';
     $file = new FileModel();
     $file->fileContent = $fileContent;
     $file->name = 'aTestName';
     $file->type = 'aTestType';
     $file->size = 500;
     $saved = $file->save();
     $this->assertTrue($saved);
     $fileId = $file->id;
     $file->forget();
     //Now retrieve the file and make sure the content matches.
     $fileModel = FileModel::getById($fileId);
     $this->assertTrue($fileModel->save());
     $file->forget();
     $fileModel = FileModel::getById($fileId);
     $this->assertEquals('testContent', $file->fileContent->content);
 }
开发者ID:RamaKavanan,项目名称:InitialVersion,代码行数:20,代码来源:ModelWithAttachmentTest.php

示例7: createEmailAttachment

 /**
  * Create FileModel
  * @param array $attachment
  * @return FileModel
  */
 protected function createEmailAttachment($attachment)
 {
     // Save attachments
     if ($attachment['filename'] != null) {
         $fileContent = new FileContent();
         $fileContent->content = $attachment['attachment'];
         $file = new FileModel();
         $file->fileContent = $fileContent;
         $file->name = $attachment['filename'];
         $file->type = ZurmoFileHelper::getMimeType($attachment['filename']);
         $file->size = strlen($attachment['attachment']);
         $saved = $file->save();
         assert('$saved');
         // Not Coding Standard
         return $file;
     } else {
         return false;
     }
 }
开发者ID:youprofit,项目名称:Zurmo,代码行数:24,代码来源:EmailArchivingJob.php

示例8: createEmailAttachment

 /**
  * Create FileModel
  * @param array $attachment
  * @param bool $base64encoded
  * @return FileModel
  */
 public static function createEmailAttachment($attachment, $base64encoded = false)
 {
     // Save attachments
     if ($attachment['filename'] != null && static::isAttachmentExtensionAllowed($attachment['filename'])) {
         $fileContent = new FileContent();
         if ($base64encoded) {
             $fileContent->content = base64_decode($attachment['attachment']);
         } else {
             $fileContent->content = $attachment['attachment'];
         }
         $file = new FileModel();
         $file->fileContent = $fileContent;
         $file->name = $attachment['filename'];
         $file->type = ZurmoFileHelper::getMimeType($attachment['filename']);
         $file->size = strlen($fileContent->content);
         $saved = $file->save();
         assert('$saved');
         // Not Coding Standard
         return $file;
     } else {
         return false;
     }
 }
开发者ID:RamaKavanan,项目名称:InitialVersion,代码行数:29,代码来源:EmailArchivingUtil.php


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