本文整理汇总了PHP中Files::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Files::save方法的具体用法?PHP Files::save怎么用?PHP Files::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Files
的用法示例。
在下文中一共展示了Files::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: post_index
public function post_index()
{
$new = new Files();
$new->save();
$response = array('success' => true, 'data' => array('id' => $new->id));
$json = json_encode($response);
return $json;
}
示例2: actionView
/**
* Вывод инфы о бане
* @param integer $id ID бана
*/
public function actionView($id)
{
// Подгружаем комментарии и файлы
$files = new Files();
//$this->performAjaxValidation($files);
$files->unsetAttributes();
$comments = new Comments();
$comments->unsetAttributes();
// Подгружаем баны
$model = Bans::model()->with('admin')->findByPk($id);
if ($model === null) {
throw new CHttpException(404, 'The requested page does not exist.');
}
$geo = false;
// Проверка прав на просмотр IP
$ipaccess = Webadmins::checkAccess('ip_view');
if ($ipaccess) {
$geo = array('city' => 'Н/А', 'region' => 'Не определен', 'country' => 'Не определен', 'lat' => 0, 'lng' => 0);
$get = @file_get_contents('http://ipgeobase.ru:7020/geo?ip=' . $model->player_ip);
if ($get) {
$xml = @simplexml_load_string($get);
if (!empty($xml->ip)) {
$geo['city'] = $xml->ip->city;
$geo['region'] = $xml->ip->region;
$geo['country'] = $xml->ip->country;
$geo['lat'] = $xml->ip->lat;
$geo['lng'] = $xml->ip->lng;
}
}
}
// Добавление файла
if (isset($_POST['Files'])) {
// Задаем аттрибуты
$files->attributes = $_POST['Files'];
$files->bid = intval($id);
if ($files->save()) {
$this->refresh();
}
}
// Добавление комментария
if (isset($_POST['Comments'])) {
//exit(print_r($_POST['Comments']));
$comments->attributes = $_POST['Comments'];
$comments->bid = $id;
if ($comments->save()) {
$this->refresh();
}
}
// Выборка комментариев
$c = new CActiveDataProvider($comments, array('criteria' => array('condition' => 'bid = :bid', 'params' => array(':bid' => $id))));
// Выборка файлов
$f = new CActiveDataProvider(Files::model(), array('criteria' => array('condition' => 'bid = :bid', 'params' => array(':bid' => $id))));
// История банов
$history = new CActiveDataProvider('Bans', array('criteria' => array('condition' => '`bid` <> :hbid AND (`player_ip` = :hip OR `player_id` = :hid)', 'params' => array(':hbid' => $id, ':hip' => $model->player_ip, ':hid' => $model->player_id)), 'pagination' => array('pageSize' => 5)));
// Вывод всего на вьюху
$this->render('view', array('geo' => $geo, 'ipaccess' => $ipaccess, 'model' => $model, 'files' => $files, 'comments' => $comments, 'f' => $f, 'c' => $c, 'history' => $history));
}
示例3: addAction
public function addAction(Files $file)
{
if ($this->request->isPost()) {
// dd($this->request->getPost());
$file->save($this->request->getPost());
EventFacade::fire('standards:addFile', $file);
return $this->redirectByRoute(['for' => 'index', 'page' => 1]);
}
$this->view->form = myForm::buildFormFromModel($file);
}
示例4: backupDB
public function backupDB()
{
$dumper = new dbMaster();
$sql = $dumper->getDump(false);
$file = new Files();
$file->name = "DB Backup " . date("d-m-Y_H_i") . ".sql";
$file->path = '.';
$file->save();
$file->writeFile($sql);
$this->DBback = $file->id;
}
示例5: action_index
public function action_index()
{
$record = new Files();
$record->parent_id = $_POST['parent_id'];
$record->text = $_POST['text'];
$record->extension = $_POST['extension'];
$record->leaf = $_POST['leaf'];
$record->save();
$array = array('success' => 'true', 'msg' => 'Record added successfully');
$json = json_encode($array);
return $json;
}
示例6: register
public static function register($name, $filepath, $extension, $module_name, $module_id)
{
$file = new Files();
$file->name = $name;
$file->path = $filepath;
$file->extension = $extension;
$file->type = Files::getType($extension);
$file->module_name = $module_name;
$file->module_id = $module_id;
$file->size = filesize(Files::fullDir($filepath));
$file->save();
return $file->id;
}
示例7: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Files();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Files'])) {
$model->attributes = $_POST['Files'];
if ($model->save()) {
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('create', array('model' => $model));
}
示例8: post_index
public function post_index()
{
$data = file_get_contents('php://input');
$temp = json_decode($data);
$new = new Files();
$new->text = $temp->text;
$new->parent_id = $temp->parentId;
$new->leaf = $temp->leaf;
$new->save();
$response = array('success' => true, 'data' => array('id' => $new->id));
$json = json_encode($response);
return $json;
}
示例9: upload
public function upload(Request $request)
{
$file = $request->file;
$imageName = md5(time() * rand(1, 100)) . '.' . $file->getClientOriginalExtension();
$f = new Files();
$f->name = $imageName;
$f->mimeType = $file->getMimeType();
$f->size = $file->getSize();
$f->user_id = 1;
$f->produto_id = $request->input('produto_id');
$file->move(base_path() . '/public/imagens/', $imageName);
$f->save();
return 'OK';
}
示例10: createMongoAction
public function createMongoAction()
{
$file = new Files();
$file->type = "video";
$file->name = "Astro Boy";
$file->year = 1952;
if ($file->save() == false) {
echo "Umh, We can't store files right now: \n";
foreach ($file->getMessages() as $message) {
echo $message, "\n";
}
} else {
echo "Great, a new file was saved successfully !";
}
}
示例11: save
public function save($runValidation = true, $attributes = NULL)
{
$class = get_class($this);
if ($class == 'Accounts') {
if (Accounts::model()->findByPk($this->id)) {
$this->isNewRecord = false;
}
}
$a = parent::save($runValidation, $attributes);
if ($a) {
//if (isset($_POST['Files'])) {
//$this->attributes = $_POST['Files'];
$tmps = CUploadedFile::getInstancesByName('Files');
// proceed if the images have been set
if (isset($tmps) && count($tmps) > 0) {
Yii::log('saved', 'info', 'app');
// go through each uploaded image
$configPath = Yii::app()->user->settings["company.path"];
foreach ($tmps as $image => $pic) {
$img_add = new Files();
$img_add->name = $pic->name;
//it might be $img_add->name for you, filename is just what I chose to call it in my model
$img_add->path = "files/";
$img_add->parent_type = get_class($this);
$img_add->parent_id = $this->id;
// this links your picture model to the main model (like your user, or profile model)
$img_add->save();
// DONE
if ($pic->saveAs($img_add->getFullFilePath())) {
// add it to the main model now
} else {
echo 'Cannot upload!';
}
}
if (isset($_FILES)) {
Yii::log(print_r($_FILES, true), 'info', 'app');
unset($_FILES);
$tmps = CUploadedFile::reset();
}
//}
}
}
//endFile
return $a;
}
示例12: save
public function save($runValidation = true, $attributes = NULL)
{
//adam:
if ($this->eavType == 'boolean') {
if ($this->value == '1') {
$this->value = 'true';
} else {
$this->value = 'false';
}
} else {
if ($this->eavType == 'file') {
$configPath = Yii::app()->user->getSetting("company.path");
$a = CUploadedFile::getInstanceByName('Settings[' . $this->id . '][value]');
if ($a) {
//exit;
$this->value = $a;
$ext = $this->value->extensionName;
//$fileName = $yiiBasepath."/files/".$configPath."/settings/".$this->id.".".$ext;
//echo $this->id.get_class($this);
$logo = new Files();
$logo->name = $this->id . "." . $ext;
//it might be $img_add->name for you, filename is just what I chose to call it in my model
$logo->path = "settings/";
$logo->parent_type = get_class($this);
$logo->parent_id = $this->id;
// this links your picture model to the main model (like your user, or profile model)
$logo->public = true;
$id = $logo->save();
// DONE
//echo $logo->id;
//Yii::app()->end();
if ($this->value->saveAs($logo->getFullFilePath())) {
$this->value = $logo->hash;
//"/files/".$configPath."/settings/".$this->id.".".$ext;
}
//Yii::app()->end();
}
}
}
return parent::save($runValidation, $attributes);
}
示例13: postStore
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function postStore()
{
if (Session::get('user_level') < Config::get('cms.addFile')) {
return Redirect::to(_l(URL::action('AdminHomeController@getIndex')))->with('message', Lang::get('admin.notPermitted'))->with('notif', 'warning');
}
$rules = array('description' => 'Required', 'url' => 'Required', 'title' => 'Required');
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::to(_l(URL::action('FileController@getCreate') . '/' . Input::get('newsId')))->withErrors($validator)->withInput();
} else {
try {
$news = News::findOrFail(Input::get('newsId'));
$file = new Files();
if (Input::get('createdAt')) {
$file->created_at = date("Y-m-d H:i:s", strtotime(Input::get('createdAt')));
} else {
$file->created_at = date("Y-m-d H:i:s", strtotime('now'));
}
$file->description = Input::get('description');
$file->published = Input::get('published');
$file->user_id = Session::get('id');
$file->url = Input::get('url');
$file->news_id = Input::get('newsId');
$file->title = Input::get('title');
$file->save();
return Redirect::to(_l(URL::action('FileController@getEdit') . "/" . $file->id))->with('message', Lang::get('admin.fileSaved'))->with('notif', 'success');
} catch (Exception $e) {
return Redirect::to(_l(URL::action('FileController@getIndex')))->with('message', Lang::get('admin.noSuchFile'))->with('notif', 'danger');
}
}
}
示例14: actionIndex
function actionIndex()
{
$this->_pathway->addStep('素材上载');
if ($this->_context->isPOST()) {
if (isset($_POST["PHPSESSID"])) {
session_id($_POST["PHPSESSID"]);
}
if (!isset($_FILES["filedata"]) || !is_uploaded_file($_FILES["filedata"]["tmp_name"]) || $_FILES["filedata"]["error"] != 0) {
return '上传失败!';
}
$filePath = rtrim(Q::ini('appini/upload/filePath'), '/\\') . DS;
Helper_Filesys::mkdirs($filePath);
//获得上传文件夹
$dir = 'data1';
$i = 0;
$handle = opendir($filePath);
while ($name = readdir($handle)) {
if ($name != "." && $name != "..") {
if (is_dir($filePath . $name) && substr($name, 0, 4) == 'data') {
$i++;
$dir = $name;
}
}
}
closedir($handle);
if ($i == 0) {
Helper_Filesys::mkdirs($filePath . $dir);
}
//判断文件中的文件是否超出限制
$j = 0;
$handle = opendir($filePath . $dir);
while ($name = readdir($handle)) {
if ($name != "." && $name != "..") {
$j++;
}
}
closedir($handle);
if ($j > 65535) {
$dir = 'data' . ($i + 1);
}
//得到编码后的文件夹及文件名
$fileNameMd5 = md5($_FILES["filedata"]["name"] . '-' . microtime(true));
$filePath .= $dir . DS . $fileNameMd5 . DS;
//保存路径名
$fileName = md5_file($_FILES["filedata"]["tmp_name"]);
//文件名
$fileExt = pathinfo($_FILES["filedata"]["name"], PATHINFO_EXTENSION);
//扩展名
//保存到数据库
$file = new Files();
$file->category_id = $this->_context->category_id;
$file->category_name = $this->_context->category_name;
$file->title = substr($_FILES["filedata"]["name"], 0, strrpos($_FILES["filedata"]["name"], '.'));
$file->name = $fileName;
$file->ext = $fileExt;
$file->size = $_FILES["filedata"]["size"];
$file->path = $filePath;
$file->status = 0;
$file->catalog_info = '';
$file->upload_username = $this->_view['currentUser']['username'];
$file->upload_at = time();
try {
$file->save();
} catch (QDB_ActiveRecord_ValidateFailedException $ex) {
if (isset($ex->validate_errors['name'])) {
return $ex->validate_errors['name'];
} else {
if (isset($ex->validate_errors['type'])) {
return $ex->validate_errors['type'];
} else {
return '上传失败!' . $ex;
}
}
}
//保存上传文件
Helper_Filesys::mkdirs($filePath);
if (!move_uploaded_file($_FILES["filedata"]["tmp_name"], $filePath . $fileName . '.' . $fileExt)) {
$file->destroy();
//保存文件失败回滚数据
return '上传失败!';
}
//返回成功结果
return 'true_' . url('admin::filecatalog/preview', array('id' => $file->id()));
} else {
$categoryId = $this->_context->category_id;
$categoryId = isset($categoryId) ? $categoryId : 1;
$category = Category::find()->getById($categoryId);
$this->_view['category'] = $category;
$categoryIds = Category::getChildrenIds($categoryId);
if (count($categoryIds)) {
//获得历史上传
$files = Files::find('category_id in (?) and upload_username=?', $categoryIds, $this->_view['currentUser']['username'])->order('upload_at desc')->top(13)->getAll();
$this->_view['files'] = $files;
}
}
}
示例15: actionUpload
public function actionUpload($id)
{
//$id=Yii::app()->user->id;
Yii::import("ext.Upload.qqFileUploader2");
$folder = Yii::getPathOfAlias('webroot') . '/users/' . Yii::app()->user->id . '/';
// folder for uploaded files
$allowedExtensions = array("jpg", "jpeg", "gif", "png");
//array("jpg","jpeg","gif","exe","mov" and etc...
$sizeLimit = 8 * 1024 * 1024;
// maximum file size in bytes
$uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
$result = $uploader->handleUpload($folder);
$fileSize = filesize($folder . $result['filename']);
//GETTING FILE SIZE
$fileName = $result['filename'];
//GETTING FILE NAME
//$img = CUploadedFile::getInstance($model,'image');
$ih = new CImageHandler();
$ih->load($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/' . $fileName)->save($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/' . $fileName)->reload()->adaptiveThumb(350, 232)->save($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/avto350_' . $fileName)->reload()->resize(304, 202)->save($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/avto304_' . $fileName);
Yii::import("application.modules.my.models.Files");
$mFile = new Files();
$mFile->uid = Yii::app()->user->id;
$mFile->file = $fileName;
$mFile->type = 'photo';
$mFile->portfolio_id = $id;
$mFile->source = 'avto';
if ($mFile->save()) {
//unlink($_SERVER['DOCUMENT_ROOT'] . '/users/'.Yii::app()->user->id.'/'.$fileName);
$result['res'] = $mFile->id;
}
$return = htmlspecialchars(json_encode($result), ENT_NOQUOTES);
echo $return;
// it's array
//echo $ret;
}