本文整理汇总了PHP中CUploadedFile::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP CUploadedFile::getInstance方法的具体用法?PHP CUploadedFile::getInstance怎么用?PHP CUploadedFile::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CUploadedFile
的用法示例。
在下文中一共展示了CUploadedFile::getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Person();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Person'])) {
$model->attributes = $_POST['Person'];
$model->job = 0;
$model->birthday = CDateTimeParser::parse($model->birthday, 'dd/MM/yyyy');
$model->avatar = CUploadedFile::getInstance($model, 'avatar');
if ($model->avatar != null) {
$avatar_name = 'image_' . $model->id . '_' . time() . '.' . $model->avatar->getExtensionName();
$model->avatar->saveAs(Yii::getPathOfAlias('webroot') . Person::M_IMAGES . $avatar_name);
$image = Yii::app()->image->load(Yii::getPathOfAlias('webroot') . Person::M_IMAGES . $avatar_name);
if (128 < $image->__get('width')) {
$image->resize(128, 128, Image::HEIGHT);
}
$image->save(Yii::getPathOfAlias('webroot') . Person::M_THUMBNAIL . $avatar_name);
// or $image->save('images/small.jpg');
$model->avatar = $avatar_name;
} else {
$model->avatar = Person::M_NOIMAGE;
}
if ($model->save()) {
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('create', array('model' => $model));
}
示例2: actionUpdate
/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'update' page.
* @param integer $id the ID of the model to be updated
*/
public function actionUpdate($id)
{
$model = new BanersElements();
$root = BanersRubrics::getRoot(new BanersRubrics());
$catalog = $root->descendants()->findAll($root->id);
$model = $this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
// set attributes from get
if (isset($_GET['BanersElements'])) {
$model->attributes = $_GET['BanersElements'];
}
if (isset($_POST['BanersElements'])) {
$model->attributes = $_POST['BanersElements'];
$model->imagefile = CUploadedFile::getInstance($model, 'imagefile');
if (isset($model->imagefile)) {
$ext = pathinfo($model->imagefile);
$model->image = $ext['extension'];
}
if ($model->save()) {
if (isset($model->imagefile) && ($modelSettings = SiteModuleSettings::model()->find('site_module_id = 15'))) {
//Загружаем картинку
$filename = $model->id . '.' . $model->image;
$filepatch = '/../uploads/filestorage/baners/elements/';
$model->imagefile->saveAs(YiiBase::getPathOfAlias('webroot') . $filepatch . $filename);
//Обработка изображения
SiteModuleSettings::model()->chgImgModel($modelSettings, 'GD', 2, $model->id);
}
$url = isset($_POST['go_to_list']) ? $this->listUrl('index') : $this->itemUrl('update', $model->id);
$this->redirect($url);
}
}
$this->render('update', array('model' => $model, 'root' => $root, 'catalog' => $catalog));
}
示例3: actionUpdate
/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
*/
public function actionUpdate($id)
{
$model = $this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['KqxsNam'])) {
$oldimage = $model->image;
$model->attributes = $_POST['KqxsNam'];
$model->image = CUploadedFile::getInstance($model, 'image');
if ($model->image != NULL) {
$folder = 'upload/' . date('Ymd');
if (!file_exists($folder)) {
mkdir($folder);
}
$model->image->saveAs($folder . '/' . $model->image);
$model->image = $folder . '/' . $model->image;
} else {
$model->image = $oldimage;
}
if ($model->save()) {
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('update', array('model' => $model));
}
示例4: actionUpdate
public function actionUpdate()
{
$model = $this->loadModel($id);
if (isset($_POST['Avatars'])) {
$model->attributes = $_POST['Avatars'];
$model->icon = CUploadedFile::getInstance($model, 'icon');
if ($model->icon) {
$sourcePath = pathinfo($model->icon->getName());
$fileName = date('m-d') . Yii::app()->user->name . '.' . $sourcePath['extension'];
$model->image = $fileName;
}
if ($model->save()) {
//Если отмечен чекбокс «удалить файл»
if ($model->del_img) {
if (file_exists($_SERVER['DOCUMENT_ROOT'] . Yii::app()->urlManager->baseUrl . '/images/' . $model->image)) {
//удаляем файл
unlink('./images/' . $model->image);
$model->image = '';
}
}
//Если поле загрузки файла не было пустым, то
if ($model->icon) {
$file = './images/' . $fileName;
$model->icon->saveAs($file);
$image = Yii::app()->image->load($file);
$image->resize(100, 100);
$image->save();
}
$this->redirect(array('update', 'id' => $model->id));
}
}
$this->render('update', array('model' => $model));
}
示例5: actionUpdate
/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
*/
public function actionUpdate($id)
{
$model = $this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Scodobjventascaract'])) {
$model->attributes = $_POST['Scodobjventascaract'];
// Verificar si existe un archivo que actualizar en la creacion
if (isset($_FILES) && $_FILES['Scodobjventascaract']['error']['imagen'] == 0) {
// Obtenemos la instancia del documento
$fDocumento = CUploadedFile::getInstance($model, 'imagen');
$sPathDocumento = $sPathFile . '/' . $model->id_cod_obj_venta . '/';
if (!file_exists($sPathDocumento)) {
mkdir($sPathDocumento, 0777, true);
}
$fDocumento->saveAs($sPathDocumento . $fDocumento->getName());
$model->imagen = $fDocumento->getName();
// $this->refresh();
}
if ($model->save()) {
$this->redirect(array('scodobjventas/' . $model->id_cod_obj_venta));
}
}
$this->render('update', array('model' => $model));
}
示例6: actionUpdate
public function actionUpdate($id)
{
$model = $this->loadModel($id);
if (isset($_POST["{$this->modelName}"])) {
$model->attributes = $_POST["{$this->modelName}"];
$newImage = isset($_FILES['Themes']) && $_FILES['Themes']['name']['upload_img'];
if ($newImage) {
// delete old image
$model->delImage();
$model->scenario = 'upload';
}
if ($model->validate()) {
if ($newImage) {
$model->upload = CUploadedFile::getInstance($model, 'upload_img');
$model->bg_image = md5(uniqid()) . '.' . $model->upload->extensionName;
}
if ($model->save()) {
if ($newImage) {
$model->upload->saveAs(Yii::getPathOfAlias($model->path) . '/' . $model->bg_image);
Yii::app()->user->setFlash('success', tt('Image successfully added', 'themes'));
} else {
Yii::app()->user->setFlash('success', tc('Success'));
}
$this->refresh();
}
}
}
$this->render('update', array('model' => $model));
}
示例7: actionUpdate
/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
*/
public function actionUpdate($id)
{
$model = $this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Links'])) {
$oldlogo = $model->logo;
$model->attributes = $_POST['Links'];
$model->update_uid = Yii::app()->user->id;
$model->update_time = date('Y-m-d H:i:s');
$image = CUploadedFile::getInstance($model, 'logo');
if ($image) {
$savename = Yii::app()->params['uploadPath'] . time() . mt_rand(1, 999) . '.' . $image->extensionName;
$model->logo = '/' . $savename;
if ($model->validate()) {
$image->saveAs($savename);
}
if (file_exists($oldlogo)) {
unlink($oldlogo);
}
} else {
$model->logo = $oldlogo;
}
if ($model->save()) {
//$this->redirect(array('view','id'=>$model->id));
Yii::app()->user->setFlash('success', '信息提交成功!');
} else {
Yii::app()->user->setFlash('success', '信息提交失败!');
}
}
$this->render('update', array('model' => $model));
}
示例8: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Article();
if (isset($_POST['Article'])) {
$model->author_id = Yii::app()->user->id;
$model->author = Yii::app()->user->nickname;
$model->attributes = $_POST['Article'];
$upimg = CUploadedFile::getInstance($model, 'img');
//获得一个CUploadedFile的实例
if (is_object($upimg) && get_class($upimg) === 'CUploadedFile') {
$model->img = './up/cover/cover_' . time() . '_' . rand(0, 9999) . '.' . $upimg->extensionName;
//定义文件保存的名称
} else {
$model->img = './up/cover/noPic.jpg';
// 若果失败则应该是什么图片
}
if ($model->save()) {
if (is_object($upimg) && get_class($upimg) === 'CUploadedFile') {
$upimg->saveAs($model->img);
// 上传图片
}
//添加成功时候的提示信息设置
/**
*setFlash getFlash hasFlash 几个方法
*/
//Yii::app()->user->setFlash('success','添加成功!');
//重定向
//$this->redirect('./index.php?r=article/index');
$this->redirect_message('新感觉发布成功!', 'success', '3', $this->createUrl('article/index'));
}
}
//设置下拉默认属性
$model->type_id = 2;
$this->render('create', array('model' => $model));
}
示例9: actionImport
public function actionImport()
{
$this->title = 'Import Komponen';
$model = new Component();
if (isset($_POST['Component'])) {
$model->file = CUploadedFile::getInstance($model, "file");
if (!$model->file) {
Yii::app()->user->setFlash('error', 'Pastikan file telah diisi.');
$this->redirect('import');
}
$filePath = Yii::getPathOfAlias('webroot') . "/imports/" . $model->file;
if ($model->file->saveAs($filePath)) {
$objPHPExcel = new PHPExcel();
$fields = array(array('name' => 'satker_code', 'col' => 0), array('name' => 'activity_code', 'col' => 1), array('name' => 'output_code', 'col' => 2), array('name' => 'suboutput_code', 'col' => 3), array('name' => 'code', 'col' => 4), array('name' => 'name', 'col' => 5));
$this->importExcelToMysql($filePath, $fields);
}
}
//get component error lists
$componentError = new ComponentError('search');
$componentError->unsetAttributes();
// clear any default values
if (isset($_GET['ComponentError'])) {
$componentError->attributes = $_GET['ComponentError'];
}
$this->render('import', array('model' => $model, 'componentError' => $componentError));
}
示例10: actionUpdate
/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
*/
public function actionUpdate($id)
{
$model = $this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Banner'])) {
$record_image = $model->image;
$model->attributes = $_POST['Banner'];
$image = CUploadedFile::getInstance($model, 'image');
if ($image) {
$genName = 'uploaded_' . date('YmdHis');
$saveName = $genName;
while (file_exists($this->upload_path . $saveName . '.' . $image->getExtensionName())) {
$saveName = $genName . '-' . rand(0, 99);
}
$model->image = $saveName . '.' . $image->getExtensionName();
}
if ($model->save()) {
if ($image) {
if (file_exists($this->upload_path . $record_image)) {
@unlink($this->upload_path . $record_image);
}
$image->saveAs($this->upload_path . $model->image);
}
$this->redirect(array('index', 'id' => $model->banner_id));
} else {
$model->image = $record_image;
}
}
$this->render('update', array('model' => $model));
}
示例11: actionUpdate
public function actionUpdate($barangayOfficialId)
{
$model = BarangayOfficials::model()->findByPk($barangayOfficialId);
if (isset($_POST['BarangayOfficials'])) {
$oldProfile = $model->profile_image;
$model->attributes = $_POST['BarangayOfficials'];
/*retrieve the uploaded file */
$uploadedFileObject = CUploadedFile::getInstance($model, 'profile_image');
if ($uploadedFileObject) {
$newFilename = uniqid() . $uploadedFileObject->getName();
$ouputfile = Yii::getPathOfAlias("imageUploads") . '/' . $newFilename;
$uploadedFileObject->saveAs($ouputfile);
$model->profile_image = $newFilename;
} else {
$model->profile_image = $oldProfile;
}
$termFrom = sprintf("first day of %s %s", $_POST['term_from_month'], $_POST['term_from_year']);
$termTo = sprintf("last day of %s %s", $_POST['term_to_month'], $_POST['term_to_year']);
$termFrom = date("Y-m-d H:i:s", strtotime($termFrom));
$termTo = date("Y-m-d H:i:s", strtotime($termTo));
$model->term_from = $termFrom;
$model->term_to = $termTo;
/*save to model*/
if ($model->save()) {
Yii::app()->user->setFlash("success", "<strong>Saved</strong> : New record saved");
$this->redirect(array("view", 'id' => $model->id));
}
}
$this->render('index', array('model' => $model));
}
开发者ID:kevindaus,项目名称:SuperSimpleBarangayInformationSystem,代码行数:30,代码来源:BarangayOfficialsController.php
示例12: actionUpdate
public function actionUpdate($id)
{
$model = $this->loadModel($id);
$file = new File();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Personnel']) && isset($_POST['File'])) {
$model->attributes = $_POST['Personnel'];
$file->attributes = $_POST['File'];
$file->file = CUploadedFile::getInstance($file, 'file');
if ($file->file != null) {
if (file_exists(Yii::app()->params['pathUpload'] . $model->pic) && $model->pic != 'noimage.jpg') {
unlink(Yii::app()->params['pathUpload'] . $model->pic);
}
if ($file->file != null) {
$filename = time() . '.' . $file->file->getExtensionName();
$file->file->saveAs(Yii::app()->params['pathUpload'] . $filename);
$model->pic = $filename;
}
}
if ($model->save()) {
$this->redirect(array('view', 'id' => $model->personnel_id));
}
}
$this->render('update', array('model' => $model, 'file' => $file));
}
示例13: actionCreate1
public function actionCreate1()
{
$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()) {
$file = CUploadedFile::getInstance($model, 'originalname');
if (is_object($file) && get_class($file) === 'CUploadedFile') {
$model->filename = $file;
} else {
$model->filename = "";
}
if (is_object($file) && get_class($file) === 'CUploadedFile') {
// again, if anything was uploaded and if we have db done then move the file from tmp to the right place
$model->filename->saveAs(Yii::app()->basePath . '/files/' . $model->filename->name);
//unlink($model->fileWithPath(Yii::app()->basePath . '/files/' . $oldfilename));
}
//$this->redirect(array('view','id'=>$model->id));
exit;
}
}
$this->render('create', array('model' => $model));
}
示例14: actionAjaxAvatar
/**
* ajax修改用户头像
*/
public function actionAjaxAvatar()
{
//获取当前用户的model
$model = $this->loadModel();
$old = $model->attributes;
$oldPath = $old['avatar'];
if ($_FILES['AdminUser']['error']['avatar'] == 0) {
//上传图片有效
$model->avatar = CUploadedFile::getInstance($model, 'avatar');
$filename = explode(".", $_FILES['AdminUser']['name']['avatar']);
$data = date("Y", time()) . '/' . date("m", time()) . '/' . date("d", time()) . '/';
$save_path = "./upload/{$data}";
//创建相应了、目录
if (!file_exists($save_path)) {
$this->mkdirs($save_path);
}
$namef = md5(uniqid(rand(), true)) . '.' . $filename[1];
$fullPath = $data . $namef;
$model->avatar->saveAs(Yii::app()->basePath . "/../upload/{$fullPath}");
@unlink(Yii::app()->basePath . "/../upload/{$oldPath}");
$model->avatar = $fullPath;
}
if ($model->save()) {
$this->updateUserInfo();
$this->redirect(array('index'));
}
}
示例15: actionUpdate
public function actionUpdate($id = null)
{
$model = Documents::model()->findByPk($id);
$flag = 0;
if (!empty($_POST['Documents'])) {
$filename_old = $model->attributes['filename'];
if (!empty(CUploadedFile::getInstance($model, 'filename')->name)) {
$model->attributes = $_POST['Documents'];
$model->filename = CUploadedFile::getInstance($model, 'filename');
$filename = $model->filename;
$document = explode('.', $model->filename->name);
$filenameType = $document[count($document) - 1];
$filenameName = md5(uniqid()) . '.' . $filenameType;
$model->type = end($document);
$model->size = $model->filename->size;
$model->md5name = $filenameName;
$model->filename = $document[count($document) - 2] . "." . $model->type;
$filenames_path = Yii::getPathOfAlias('webroot') . '/upload/documents/' . $filenameName;
$flag = 1;
} else {
$model->attributes = $_POST['Documents'];
$model->filename = $filename_old;
}
$model->updated = time();
if ($model->save()) {
Yii::app()->user->setFlash('success', translate('Cập nhật thành công.'));
if ($flag == 1) {
$filename->saveAs($filenames_path);
}
$this->redirect(PIUrl::createUrl('/admin/Documents/'));
}
}
$dataCategories = categoriesDocuments::model()->getCategoriesDocument();
$this->render('update', array('model' => $model, 'dataCategory' => $dataCategories));
}