本文整理汇总了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));
}
示例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));
}