本文整理汇总了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;
}
示例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;
}
示例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);
}
}
示例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);
}
}
}
示例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);
}
示例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;
}
}
示例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;
}
}