本文整理汇总了PHP中Attachments::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Attachments::save方法的具体用法?PHP Attachments::save怎么用?PHP Attachments::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Attachments
的用法示例。
在下文中一共展示了Attachments::save方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate($id = '')
{
if ($id) {
$model = $this->loadModel($id);
} else {
$model = new Attachments();
}
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Attachments'])) {
$model->attributes = $_POST['Attachments'];
if ($model->save()) {
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('create', array('model' => $model));
}
示例2: executeUpload
public function executeUpload(sfWebRequest $request)
{
$file = $request->getFiles();
$filename = mt_rand(111111, 999999) . '-' . $file['Filedata']['name'];
if (move_uploaded_file($file['Filedata']['tmp_name'], sfConfig::get('sf_upload_dir') . '/attachments/' . $filename)) {
$bind_id = $request->getParameter('bind_id');
if ((int) $bind_id == 0) {
$bind_id = -$this->getUser()->getAttribute('id');
}
$a = new Attachments();
$a->setFile($filename);
$a->setBindType($request->getParameter('bind_type'));
$a->setBindId($bind_id);
$a->save();
}
exit;
}
示例3: taskimage
public function taskimage()
{
$doc_id = Input::get('doc_id');
$custom1 = Input::get('custom1');
$custom2 = Input::get('custom2');
$custom3 = Input::get('custom3');
Session::put('custom1', $custom1);
Session::put('custom2', $custom2);
Session::put('custom3', $custom3);
//Image Upload
foreach (Input::file('file') as $file) {
$rules = array('file' => 'required|mimes:png,gif,jpeg,jpg|max:900000000000000000000');
$validator = \Validator::make(array('file' => $file), $rules);
$destine = public_path() . "/uploads";
if ($validator->passes()) {
$ext = $file->guessClientExtension();
// (Based on mime type)
$ext = $file->getClientOriginalExtension();
// (Based on filename)
$filename = $file->getClientOriginalName();
$archivo = value(function () use($file) {
$filename = str_random(10) . '.' . $file->getClientOriginalExtension();
return strtolower($filename);
});
$archivo = value(function () use($file) {
$date = date('m-d-Y-h-i-s', time());
$filename = $date . "-" . $file->getClientOriginalName();
return strtolower($filename);
});
$attach = new Attachments();
$attach->doc_id = $doc_id;
$attach->data = $archivo;
$attach->saved = 1;
$attach->save();
$filename = $doc_id . "_" . $attach->id;
$file->move($destine, $archivo);
$target_folder = $destine;
$upload_image = $target_folder . "/" . $archivo;
$thumbnail = $target_folder . "/resize" . $archivo;
$actual = $target_folder . "/" . $archivo;
// THUMBNAIL SIZE
list($width, $height) = getimagesize($upload_image);
$newwidth = $width;
$newheight = $height;
while ($newheight > 525) {
$newheight = $newheight * 0.8;
$newwidth = $newwidth * 0.8;
}
$source = $upload_image;
$ext = strtolower($ext);
$thumb = imagecreatetruecolor($newwidth, $newheight);
if ($ext == "jpg" || $ext == "jpeg") {
$source = imagecreatefromjpeg($upload_image);
} elseif ($ext == "png") {
$source = imagecreatefrompng($upload_image);
} elseif ($ext == "gif") {
$source = imagecreatefromgif($upload_image);
} else {
continue;
}
// RESIZE
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// MAKE NEW FILES
if ($ext == "jpg" || $ext == "jpeg") {
imagejpeg($thumb, $thumbnail, 100);
} elseif ($ext == "png") {
imagepng($thumb, $thumbnail, 9);
} elseif ($ext == "gif") {
imagegif($thumb, $thumbnail, 100);
} else {
echo "An invalid image";
}
unlink($actual);
// FILE RENAMES
rename($thumbnail, $actual);
} else {
$errors = $validator->errors();
Session::put('imgerror', 'Invalid file.');
}
}
Session::put('imgsuccess', 'Files uploaded.');
if (Session::get('imgerror')) {
Session::forget('imgsuccess');
}
return Redirect::back()->withInput();
//End Image Upload
}
示例4: setValues
public static function setValues($fields, $bind_id, $bind_type, $sf_user, $request)
{
$extra_fields = ExtraFieldsList::getFieldsByType($bind_type, $sf_user, false, array('all' => true));
foreach ($extra_fields as $ef) {
//escape view only fields
if (in_array($sf_user->getAttribute('users_group_id'), explode(',', $ef['view_only_access']))) {
continue;
}
if (isset($fields[$ef['id']])) {
$v = $fields[$ef['id']];
} else {
$v = '';
}
$v = app::strip_tags($v);
if ($ef['type'] == 'file') {
$files = $request->getFiles();
if ($extra_fields_files_delete = $request->getParameter('extra_fields_files_delete')) {
if (isset($extra_fields_files_delete[$ef['id']])) {
if ($a = Doctrine_Core::getTable('Attachments')->find($extra_fields_files_delete[$ef['id']])) {
if (is_file($file_path = sfConfig::get('sf_upload_dir') . '/attachments/' . $a->getFile())) {
unlink($file_path);
}
$a->delete();
}
}
}
if ($extra_fields_files = $request->getParameter('extra_fields_files')) {
if (isset($extra_fields_files[$ef['id']])) {
$v = $extra_fields_files[$ef['id']];
}
}
if (strlen($files['extra_fields'][$ef['id']]['name']) > 0) {
if ($v > 0) {
if ($a = Doctrine_Core::getTable('Attachments')->find($v)) {
if (is_file($file_path = sfConfig::get('sf_upload_dir') . '/attachments/' . $a->getFile())) {
unlink($file_path);
}
$a->delete();
}
}
$file = $files['extra_fields'][$ef['id']];
$filename = rand(111111, 999999) . '-' . $file['name'];
move_uploaded_file($file['tmp_name'], sfConfig::get('sf_upload_dir') . '/attachments/' . $filename);
$a = new Attachments();
$a->setFile($filename);
$a->setBindType('extra_fields');
$a->setBindId($ef['id']);
$a->save();
$v = $a->getId();
}
} elseif ($ef['type'] == 'date_dropdown') {
$v = implode('-', $v);
} elseif ($ef['type'] == 'date_range') {
$v = implode('|', $v);
} elseif ($ef['type'] == 'checkbox' and is_array($v)) {
$v = implode("\n", $v);
} elseif (is_array($v)) {
$v = implode(',', $v);
}
$f = Doctrine_Core::getTable('ExtraFieldsList')->createQuery()->addWhere('bind_id=?', $bind_id)->addWhere('extra_fields_id=?', $ef['id'])->fetchOne();
if ($f) {
$f->setValue($v);
$f->save();
} else {
$f = new ExtraFieldsList();
$f->setBindId($bind_id);
$f->setExtraFieldsId($ef['id']);
$f->setValue($v);
$f->save();
}
}
}
示例5: actionUpload
public function actionUpload()
{
$uptype = zmf::filterInput($_GET['type'], 't', 1);
$logid = zmf::filterInput($_GET['id']);
//所属对象
$reImgsize = zmf::filterInput($_GET['imgsize']);
//返回图片的尺寸
$fileholder = zmf::filterInput($_GET['fileholder'], 't', 1);
//上传控件的ID
//将ads替换为flash
if (!isset($uptype) or !in_array($uptype, array('siteinfo', 'post'))) {
$this->jsonOutPut(0, '请设置上传所属类型' . $uptype);
}
if (Yii::app()->request->getParam('PHPSESSID')) {
Yii::app()->session->close();
$res = Yii::app()->session->setSessionID(Yii::app()->request->getParam('PHPSESSID'));
Yii::app()->session->open();
}
if (Yii::app()->user->isGuest) {
$this->jsonOutPut(0, Yii::t('default', 'loginfirst'));
}
if (!$fileholder) {
$fileholder = 'filedata';
}
if (!isset($_FILES[$fileholder]) || !is_uploaded_file($_FILES[$fileholder]["tmp_name"]) || $_FILES[$fileholder]["error"] != 0) {
$this->jsonOutPut(0, '无效上传,请重试');
}
$model = new Attachments();
$img = CUploadedFile::getInstanceByName($fileholder);
$ext = $img->getExtensionName();
$size = $img->getSize();
if ($size > zmf::config('imgMaxSize')) {
$this->jsonOutPut(0, '上传文件最大尺寸为:' . tools::formatBytes(zmf::config('imgMaxSize')));
}
$upExt = zmf::config("imgAllowTypes");
if (!preg_match('/^(' . str_replace('*.', '|', str_replace(';', '', $upExt)) . ')$/i', $ext)) {
$this->jsonOutPut(0, '上传文件扩展名必需为:' . $upExt);
}
$sizeinfo = getimagesize($_FILES[$fileholder]["tmp_name"]);
if ($sizeinfo['0'] < zmf::config('imgMinWidth') or $sizeinfo[1] < zmf::config('imgMinHeight')) {
$this->jsonOutPut(0, "要求上传的图片尺寸,宽不能不小于" . zmf::config('imgMinWidth') . "px,高不能小于" . zmf::config('imgMinHeight') . "px.");
}
$ctime = zmf::now();
$dirs = zmf::uploadDirs($ctime, 'app', $uptype, null, true);
$fileName = uniqid() . '.' . $ext;
$origin = $dirs['origin'];
unset($dirs['origin']);
$uploadedFiles = array();
$uploadedFiles[] = array('from' => $origin . $fileName, 'to' => zmf::ftpPath($ctime, $uptype, 'origin') . $fileName);
if (move_uploaded_file($_FILES[$fileholder]["tmp_name"], $origin . $fileName)) {
$data = array();
$status = Posts::STATUS_PASSED;
$data['uid'] = Yii::app()->user->id;
$data['logid'] = $logid;
$data['filePath'] = $fileName;
$data['fileDesc'] = $fileName;
$data['classify'] = $uptype;
$data['covered'] = '0';
$data['cTime'] = time();
$data['status'] = $status;
$data['width'] = $sizeinfo[0];
$data['height'] = $sizeinfo[1];
$data['size'] = $size;
$model->attributes = $data;
if ($model->validate()) {
if ($model->save()) {
$image = Yii::app()->image->load($origin . $fileName);
$_quality = zmf::config('imgQuality');
$quality = isset($quality) ? $quality : 100;
foreach ($dirs as $dk => $_dir) {
if ($dk < 600) {
$image->smart_resize($dk, $dk * 0.75)->quality($quality);
} else {
$image->resize($dk, $dk)->quality($quality);
}
$image->save($_dir . $fileName);
$_todir = zmf::ftpPath($ctime, $uptype, $dk);
$uploadedFiles[] = array('id' => $model->id, 'from' => $_dir . $fileName, 'to' => $_todir . $fileName);
}
$imgsize = $reImgsize > 0 ? $reImgsize : 170;
$returnimg = zmf::uploadDirs($ctime, 'site', $uptype, $imgsize) . $fileName;
$outPutData = array('status' => 1, 'attachid' => $model->id, 'imgsrc' => $returnimg);
$json = CJSON::encode($outPutData);
echo $json;
} else {
$this->jsonOutPut(0, '写入数据库错误');
}
} else {
$this->jsonOutPut(0, '数据验证错误');
}
}
}
示例6: actionUpload
public function actionUpload()
{
$uptype = zmf::filterInput($_GET['type'], 't', 1);
$logid = zmf::filterInput($_GET['id']);
//所属对象
$reImgsize = zmf::filterInput($_GET['imgsize']);
//返回图片的尺寸
$fileholder = zmf::filterInput($_GET['fileholder'], 't', 1);
//上传控件的ID
if (!isset($uptype) or !in_array($uptype, array('posts', 'siteinfo'))) {
$this->jsonOutPut(0, '请设置上传所属类型' . $uptype);
}
if (Yii::app()->request->getParam('PHPSESSID')) {
Yii::app()->session->close();
$res = Yii::app()->session->setSessionID(Yii::app()->request->getParam('PHPSESSID'));
Yii::app()->session->open();
}
if (Yii::app()->user->isGuest) {
$this->jsonOutPut(0, '请先登录');
}
if (!$fileholder) {
$fileholder = 'filedata';
}
if (!isset($_FILES[$fileholder]) || !is_uploaded_file($_FILES[$fileholder]["tmp_name"]) || $_FILES[$fileholder]["error"] != 0) {
$this->jsonOutPut(0, '无效上传,请重试');
}
$img = CUploadedFile::getInstanceByName($fileholder);
$ext = $img->getExtensionName();
$size = $img->getSize();
if ($size > zmf::config('imgMaxSize')) {
$this->jsonOutPut(0, '上传文件最大尺寸为:' . tools::formatBytes(zmf::config('imgMaxSize')));
}
$upExt = zmf::config("imgAllowTypes");
if (!preg_match('/^(' . str_replace('*.', '|', str_replace(';', '', $upExt)) . ')$/i', $ext)) {
$this->jsonOutPut(0, '上传文件扩展名必需为:' . $upExt);
}
$sizeinfo = getimagesize($_FILES[$fileholder]["tmp_name"]);
if ($sizeinfo['0'] < zmf::config('imgMinWidth') or $sizeinfo[1] < zmf::config('imgMinHeight')) {
$this->jsonOutPut(0, "要求上传的图片尺寸,宽不能不小于" . zmf::config('imgMinWidth') . "px,高不能小于" . zmf::config('imgMinHeight') . "px.");
}
$ctime = zmf::now();
$dir = zmf::uploadDirs($ctime, 'app', $uptype);
zmf::createUploadDir($dir);
$fileName = zmf::uuid() . '.' . $ext;
$origin = $dir;
if (move_uploaded_file($_FILES[$fileholder]["tmp_name"], $origin . $fileName)) {
$data = array();
$status = Posts::STATUS_NOTPASSED;
$data['uid'] = zmf::uid();
$data['logid'] = $logid;
$data['filePath'] = $fileName;
$data['fileDesc'] = '';
$data['classify'] = $uptype;
$data['covered'] = '0';
$data['cTime'] = $ctime;
$data['status'] = $status;
$data['width'] = $sizeinfo[0];
$data['height'] = $sizeinfo[1];
$data['size'] = $size;
$model = new Attachments();
$model->attributes = $data;
if ($model->save()) {
$attachid = $model->id;
$returnImgDir = zmf::getUpExtraUrl($ctime);
$saveName = $uptype . '/' . $returnImgDir . '/' . $fileName;
$accessKey = zmf::config('qiniuAk');
$secretKey = zmf::config('qiniuSk');
$bucket = zmf::config('qiniuBucket');
if ($accessKey && $secretKey && $bucket) {
$auth = new Auth($accessKey, $secretKey);
$token = $auth->uploadToken($bucket);
$uploadMgr = new UploadManager();
list($ret, $err) = $uploadMgr->putFile($token, $saveName, $origin . $fileName);
if ($err !== null) {
zmf::fp(var_export($err));
$this->jsonOutPut(0, '上传至云服务错误');
}
}
$returnimg = zmf::uploadDirs($ctime, 'site', $uptype) . $fileName;
$returnimg = zmf::getThumbnailUrl($returnimg, '650', $uptype);
$_attr = array('id' => $attachid, 'imgurl' => $returnimg);
$html = '';
if ($uptype == 'posts') {
//$html= $this->renderPartial('/posts/_addImg',array('data'=>$_attr),true);
}
$outPutData = array('status' => 1, 'attachid' => $attachid, 'imgsrc' => $returnimg, 'html' => $html);
$json = CJSON::encode($outPutData);
echo $json;
} else {
$this->jsonOutPut(0, '写入数据库错误');
}
}
}
示例7: executeCopyAttachments
public function executeCopyAttachments(sfWebRequest $request)
{
if (count($attachments_ids = explode(',', $request->getParameter('attachments'))) > 0) {
$attachments = Doctrine_Core::getTable('Attachments')->createQuery()->whereIn('id', $attachments_ids)->execute();
foreach ($attachments as $a) {
if (Doctrine_Core::getTable('Attachments')->createQuery()->addWhere('SUBSTRING(file,8)=?', substr($a->getFile(), 7))->addWhere('bind_type=?', $request->getParameter('to'))->addWhere('bind_id=?', -$this->getUser()->getAttribute('id'))->count() == 0) {
$new_filename = rand(111111, 999999) . '-' . substr($a->getFile(), 7);
copy(sfConfig::get('sf_upload_dir') . '/attachments/' . $a->getFile(), sfConfig::get('sf_upload_dir') . '/attachments/' . $new_filename);
$aa = new Attachments();
$aa->setFile($new_filename);
$aa->setInfo($a->getInfo());
$aa->setBindType($request->getParameter('to'));
$aa->setBindId(-$this->getUser()->getAttribute('id'));
$aa->save();
}
}
}
exit;
}
示例8: addPostImg
public function addPostImg()
{
$logid = zmf::filterInput($_GET['id']);
$uptype = zmf::filterInput($_GET['imgtype'], 't', 1);
if (!$uptype) {
$this->jsonOutPut(0, '不允许的分类');
}
if (!$logid) {
$logid = 0;
}
$ctime = time();
$dirs = zmf::upDirs($ctime, 'app', $uptype);
$origin = $dirs['origin'] . '/';
unset($dirs['origin']);
zmf::createUploadDir($origin);
$img = CUploadedFile::getInstanceByName('filedata');
if ($img->getHasError()) {
$this->jsonOutPut(0, '上传有误,请重试');
}
$ext = $img->getExtensionName();
$upExt = zmf::config("imgAllowTypes");
if (!preg_match('/^(' . str_replace('*.', '|', str_replace(';', '', $upExt)) . ')$/i', $ext)) {
$this->jsonOutPut(0, '上传文件扩展名必需为:' . $upExt);
}
$size = $img->getSize();
if ($size > zmf::config('imgMaxSize')) {
$this->jsonOutPut(0, '上传文件最大尺寸为:' . tools::formatBytes(zmf::config('imgMaxSize')));
}
$_imgInfo = getimagesize($_FILES["filedata"]["tmp_name"]);
if ($_imgInfo['0'] < zmf::config('imgMinWidth') or $_imgInfo[1] < zmf::config('imgMinHeight')) {
$this->jsonOutPut(0, "宽不能小于" . zmf::config('imgMinWidth') . "px<br/>高不能小于" . zmf::config('imgMinHeight') . "px");
}
$fileName = uniqid() . '.' . $ext;
// $_extra=self::getUpExtraUrl($ctime);
// $filePath=$_extra.'/'.$fileName;
if (move_uploaded_file($_FILES["filedata"]["tmp_name"], $origin . $fileName)) {
$uid = Yii::app()->user->id;
$uid = 1;
$data['uid'] = $uid;
$data['logid'] = $logid;
$data['filePath'] = $fileName;
$data['fileDesc'] = $fileName;
$data['classify'] = $uptype;
$data['covered'] = '0';
$data['cTime'] = $ctime;
$data['status'] = Posts::STATUS_DELED;
$model = new Attachments();
$model->attributes = $data;
if ($model->validate()) {
if (!$model->save()) {
$this->jsonOutPut(0, '写入数据库出错');
} else {
$attachid = $model->id;
}
} else {
$this->jsonOutPut(0, '数据验证错误');
}
$image = Yii::app()->image->load($origin . $fileName);
$_quality = zmf::config('imgQuality');
$quality = isset($quality) ? $quality : 100;
foreach ($dirs as $dk => $_dir) {
zmf::createUploadDir($_dir);
if ($_imgInfo[0] < $dk && $_imgInfo[1] < $dk) {
$image->resize($_imgInfo[0], $_imgInfo[1])->quality($quality);
} else {
$image->smart_resize($dk, ceil($dk * 0.75))->quality($quality);
}
$image->save($_dir . '/' . $fileName, false);
}
$_dir = zmf::upDirs($ctime, 'site', $uptype, '600');
$returnimg = $_dir . '/' . $fileName;
$data = array('imgsrc' => $returnimg, 'attachid' => $attachid);
$this->jsonOutPut(1, $data);
}
}
示例9: edit_submit
public function edit_submit()
{
$id = Input::get('id');
$purchase = Purchase::find(Input::get('id'));
$document = Document::where('pr_id', Input::get('id'))->first();
$purchase->projectPurpose = strip_tags(Input::get('projectPurpose'));
$purchase->sourceOfFund = strip_tags(Input::get('sourceOfFund'));
$purchase->office = Input::get('office');
$purchase->requisitioner = Input::get('requisitioner');
$purchase->dateRequested = Input::get('dateRequested');
$purchase->dateReceived = Input::get('dateReceived');
$purchase->controlNo = Input::get('controlNo');
$purchase_save = $purchase->save();
if ($purchase_save) {
$document->pr_id = $purchase->id;
$document_save = $document->save();
if ($document_save) {
//Image Upload
$doc_id = $document->id;
foreach (Input::file('file') as $file) {
$rules = array('file' => 'required|mimes:png,gif,jpeg,jpg|max:90000000000000000000');
$validator = Validator::make(array('file' => $file), $rules);
$destine = public_path() . "/uploads";
if ($validator->passes()) {
$ext = $file->guessClientExtension();
$ext = $file->getClientOriginalExtension();
$filename = $file->getClientOriginalName();
$archivo = value(function () use($file) {
$date = date('m-d-Y-h-i-s', time());
$filename = $date . "-" . $file->getClientOriginalName();
return strtolower($filename);
});
$attach = new Attachments();
$attach->doc_id = $doc_id;
$attach->data = $archivo;
$attach->save();
$filename = $doc_id . "_" . $attach->id;
$file->move($destine, $archivo);
$target_folder = $destine;
$upload_image = $target_folder . "/" . $archivo;
$thumbnail = $target_folder . "/resize" . $archivo;
$actual = $target_folder . "/" . $archivo;
// THUMBNAIL SIZE
list($width, $height) = getimagesize($upload_image);
$newwidth = $width;
$newheight = $height;
while ($newheight > 525) {
$newheight = $newheight * 0.8;
$newwidth = $newwidth * 0.8;
}
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = $upload_image;
$ext = strtolower($ext);
if ($ext == "jpg" || $ext == "jpeg") {
$source = imagecreatefromjpeg($upload_image);
} elseif ($ext == "png") {
$source = imagecreatefrompng($upload_image);
} elseif ($ext == "gif") {
$source = imagecreatefromgif($upload_image);
} else {
continue;
}
// RESIZE
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// MAKE NEW FILES
if ($ext == "jpg" || $ext == "jpeg") {
imagejpeg($thumb, $thumbnail, 100);
} elseif ($ext == "png") {
imagepng($thumb, $thumbnail, 9);
} elseif ($ext = "gif") {
imagegif($thumb, $thumbnail, 100);
} else {
echo "Invalid image";
}
unlink($actual);
// FILE RENAMES
rename($thumbnail, $actual);
} else {
//Does not pass validation
$errors = $validator->errors();
Session::put('imgerror', 'Invalid file.');
break;
}
}
if (Session::get('imgerror') && Input::hasfile('file')) {
//Image Error Return
// Set Main Error
$message = "Failed to save purchase request.";
Session::put('main_error', $message);
// Get Other Error Messages
$error_projectPurpose = $purchase->validationErrors->first('projectPurpose');
$error_projectType = $purchase->validationErrors->first('projectType');
$error_sourceOfFund = $purchase->validationErrors->first('sourceOfFund');
$error_office = $purchase->validationErrors->first('office');
$error_requisitioner = $purchase->validationErrors->first('requisitioner');
$error_dateRequested = $purchase->validationErrors->first('dateRequested');
$error_dateReceived = $purchase->validationErrors->first('dateReceived');
// Inserting Error Message To a Session
Session::put('error_projectPurpose', $error_projectPurpose);
Session::put('error_sourceOfFund', $error_sourceOfFund);
//.........这里部分代码省略.........