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


PHP FileUpload::isNull方法代码示例

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


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

示例1: actionUpdate

 public function actionUpdate($id)
 {
     $model = $this->loadBiz(trim($id));
     $model->setScenario('sell');
     $this->performAjaxValidation($model);
     if (!empty($_POST)) {
         $model->attributes = $_POST['ARBiz'];
         //            dump($_FILES);
         //            控制器中使用实例如下:
         $upload = new FileUpload(array($model, 'license_photo'), 'upload/groupon');
         //model处理文件上传  $upload = new FileUpload(array($model,'pic'),'upload/goods');
         if (!$upload->isNull()) {
             if ($filename = $upload->save()) {
                 $model->license_photo = $filename;
                 //                      dump($filename);
             } else {
                 print_r($upload->getErrors());
                 throw new CHttpException('300', '文件上传失败');
             }
         }
         //            dump($model->attributes);
         if ($model->save()) {
             //                $return_url = $_POST['return_url'];
             $this->redirect(array('index'));
         }
     }
     $this->render('update', array('model' => $model));
 }
开发者ID:yinhe,项目名称:yincart,代码行数:28,代码来源:BizController.php

示例2: actionUpdate

 public function actionUpdate($id)
 {
     $model = ARGroupon::model()->findByPk($id);
     if ($model == null) {
         $this->go('该商品不存在', Yii::app()->request->urlReferrer);
     }
     $model->setScenario('sell');
     $this->performAjaxValidation($model);
     if (!empty($_POST['ARGroupon'])) {
         //            dump($_FILES);
         //            dump($_POST);exit;
         $model->attributes = $_POST['ARGroupon'];
         if ($model->validate()) {
             $fileUpload = new FileUpload(array($model, 'image'), 'upload/groupon');
             if (!$fileUpload->isNull()) {
                 $filename = $fileUpload->save();
                 if ($filename) {
                     $model->image = $filename;
                 } else {
                     dump($fileUpload->getErrors());
                     throw new CHttpException(300, '图片上传出错');
                 }
             }
             $model->begin_time = strtotime($model->begin_time);
             $model->end_time = strtotime($model->end_time);
             $model->expire_time = strtotime($model->expire_time);
             if ($model->save()) {
                 Yii::app()->user->setFlash('success', '商品修改成功');
                 //                    $url = $_POST['return_url'];
                 //                    $this->go('商品修改成功', $url, 'success');
             }
         }
     }
     $this->render('update', array('model' => $model));
 }
开发者ID:jackycgq,项目名称:advanced,代码行数:35,代码来源:GrouponController.php

示例3: actionUpload

 public function actionUpload()
 {
     Yii::import("xupload.models.XUploadForm");
     //Here we define the paths where the files will be stored temporarily
     $path = Yii::app()->getBasePath() . "/../";
     $publicPath = 'http://img.yincart.com';
     //
     //	if (!file_exists($path)) {
     //	    mkdir($path, 0777, true);
     //	}
     //	$ymd = date("Ymd");
     //	$path .= $ymd . '/';
     //	if (!file_exists($path)) {
     //	    mkdir($path, 0777, true);
     //	}
     //This is for IE which doens't handle 'Content-type: application/json' correctly
     header('Vary: Accept');
     if (isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false) {
         header('Content-type: application/json');
     } else {
         header('Content-type: text/plain');
     }
     //Here we check if we are deleting and uploaded file
     if (isset($_GET["_method"])) {
         if ($_GET["_method"] == "delete") {
             if ($_GET["file"][0] !== '.') {
                 $file = $path . $_GET["file"];
                 if (is_file($file)) {
                     unlink($file);
                 }
             }
             echo json_encode(true);
         }
     } else {
         $model = new XUploadForm();
         $upload = new FileUpload(array($model, 'file'), 'upload/groupon');
         if (!$upload->isNull()) {
             $model->mime_type = $upload->instance->getType();
             $model->size = $upload->instance->getSize();
             $model->name = $upload->instance->getName();
             if ($model->validate()) {
                 $filename = $upload->save();
                 //                }
                 //            }
                 //	    $model->file = CUploadedFile::getInstance($model, 'file');
                 //We check that the file was successfully uploaded
                 //	    if ($model->file !== null) {
                 //Grab some data
                 //		$model->mime_type = $model->file->getType();
                 //		$model->size = $model->file->getSize();
                 //		$model->name = $model->file->getName();
                 //(optional) Generate a random name for our file
                 //		$filename = date("YmdHis") . '_' . rand(10000, 99999);
                 //		$filename .= "." . $model->file->getExtensionName();
                 //		$filename =  $ymd . '/' . $filename;
                 //		if ($model->validate()) {
                 //Move our file to our temporary dir
                 //		    $model->file->saveAs($path . $filename);
                 //		    chmod($path . $filename, 0777);
                 //here you can also generate the image versions you need
                 //using something like PHPThumb
                 //Now we need to save this path to the user's session
                 if (Yii::app()->user->hasState('images')) {
                     $userImages = Yii::app()->user->getState('images');
                 } else {
                     $userImages = array();
                 }
                 $userImages[] = array("path" => $path . $filename, "thumb" => $path . $filename, "filename" => $filename, "url" => $publicPath . '/' . $filename, 'size' => $model->size, 'mime' => $model->mime_type, 'name' => $model->name);
                 Yii::app()->user->setState('images', $userImages);
                 //Now we need to tell our widget that the upload was succesfull
                 //We do so, using the json structure defined in
                 // https://github.com/blueimp/jQuery-File-Upload/wiki/Setup
                 echo json_encode(array(array("name" => $model->name, "type" => $model->mime_type, "size" => $model->size, "url" => $publicPath . '/' . $filename, "thumbnail_url" => $publicPath . '/' . "{$filename}", "delete_url" => $this->createUrl("upload", array("_method" => "delete", "file" => $filename)), "delete_type" => "POST")));
             } else {
                 //If the upload failed for some reason we log some data and let the widget know
                 echo json_encode(array(array("error" => $model->getErrors('file'))));
                 Yii::log("XUploadAction: " . CVarDumper::dumpAsString($model->getErrors()), CLogger::LEVEL_ERROR, "xupload.actions.XUploadAction");
             }
         } else {
             throw new CHttpException(500, "Could not upload file");
         }
     }
 }
开发者ID:yinhe,项目名称:yincart,代码行数:83,代码来源:ContractController.php


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