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


PHP FileUpload::validate方法代码示例

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


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

示例1: actionUpload

 /** 
  * Uploads the xls file on system.
  * The browser displays the result of this operation.
  */
 public function actionUpload()
 {
     if (!Yii::app()->user->checkAccess('loadExcel')) {
         throw new CHttpException(403, Yii::t('http_status', '403'));
     }
     $upload = false;
     $model = new FileUpload();
     if (isset($_POST['FileUpload'])) {
         $model->attributes = $_POST['FileUpload'];
         if ($model->validate()) {
             $upload = true;
             $model->uploaded_file = CUploadedFile::getInstance($model, 'uploaded_file');
             $model->uploaded_file->saveAs(Yii::app()->basePath . '/../excel_uploads/' . $model->uploaded_file);
             $this->render('upload', array('model' => $model, 'upload' => $upload, 'filename' => $model->uploaded_file));
             Yii::app()->end();
         }
     }
     $this->render('upload', array('model' => $model, 'upload' => $upload));
 }
开发者ID:Gnafu,项目名称:wiz,代码行数:23,代码来源:FileUploadController.php

示例2: actionFileupload

 public function actionFileupload()
 {
     $model = new FileUpload();
     // uncomment the following code to enable ajax-based validation
     /*
     if(isset($_POST['ajax']) && $_POST['ajax']==='file-upload-file_upload-form')
     {
     		echo CActiveForm::validate($model);
     		Yii::app()->end();
     }
     */
     $rows = array();
     $columns = array();
     $slides = array();
     if (isset($_POST['FileUpload'])) {
         $model->attributes = $_POST['FileUpload'];
         if ($model->validate()) {
             //  $slides=$this->pptx_to_text(Yii::app()->baseUrl."/files/samplePowerPoint.pptx");
             $file = CUploadedFile::getInstance($model, 'file');
             //$ext="pptx";
             $ext = pathinfo($file->getName(), PATHINFO_EXTENSION);
             if ($ext == "pptx") {
                 $slides = $this->pptx_to_text($file->getTempName());
                 //$slides=$this->pptx_to_text("files/samplePowerPoint.pptx");
             } else {
                 if ($ext == "xls" || $ext == "xlsx") {
                     Yii::import('ext.phpexcelreader.JPhpExcelReader');
                     try {
                         $data = new JPhpExcelReader($file->getTempName());
                     } catch (Exception $e) {
                         $model->addError("file", $e->getMessage());
                         //echo "Error:".$e->getMessage();
                     }
                     $i = 0;
                     /* 
                     							  echo "Data:<pre>";
                     print_r($data);
                     echo "</pre>";
                     */
                     //exit;
                     foreach ($data->sheets as $k1 => $s) {
                         /*
                         echo "Cells:<pre>";
                         							print_r($s);
                         echo "</pre>";
                         */
                         if (isset($s['cells'])) {
                             for ($j = 0; $j < count($s['cells']); $j++) {
                                 if ($j == 0) {
                                     $columns = $s['cells'][$j + 1];
                                 } else {
                                     for ($k = 0; $k < count($columns); $k++) {
                                         $rows[$k1][$i][$columns[$k + 1]] = $s['cells'][$j + 1][$k + 1];
                                         /*                                    
                                         												$rows[$k1][$i][$columns[$k+1]]=array(
                                         																      'value'=>$s['cells'][$j+1][$k+1],
                                         																      'style'=>''
                                         																    );  
                                         */
                                     }
                                     $i++;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->render('file_upload', array('model' => $model, 'sheets' => $rows, 'columns' => $columns, 'slides' => $slides));
 }
开发者ID:anmolview,项目名称:yiidemos,代码行数:71,代码来源:SiteController.php


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