YII2+jquery.Fileupload文件上传
1、单个文件上传
首先建立一个模型models/UploadForm.php,内容如下
创新互联从2013年成立,是专业互联网技术服务公司,拥有项目成都网站建设、网站建设网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元阳高做网站,已为上家服务,为阳高各地企业和个人服务,联系电话:18980820575
namespace app\models; use yii\base\Model; use yii\web\UploadedFile; /** * UploadForm is the model behind the upload form. */ class UploadForm extends Model{ /** * @var UploadedFile file attribute */ public $file; /** * @return array the validation rules. */ public function rules() { return [ [['file'], 'file'], ]; } }
再建立一个视图文件,内容如下
上传成功
最后建立控制器文件,内容如下
//获取新单据号 public function actionInclude(){ $model = new UploadForm(); if (Yii::$app->request->isPost) { $model->file = UploadedFile::getInstance($model, 'file'); $allow = array('xls','xlsx'); if ($model->file && in_array($model->file->extension,$allow)) { $result = $model->file->saveAs('uploads/' . $model->file->baseName . '.' . $model->file->extension); if($result){ echo '200'; exit; }else{ echo '上传失败'; exit; } }else{ echo '格式不对'; exit; } } return $this->render('includeView', ['model' => $model]); }
YII2上传:http://www.yiichina.com/tutorial/328
fileupload:http://bbs.9ria.com/thread-245293-1-1.html
http://www.jq22.com/jquery-info230
本文名称:YII2+jquery.Fileupload文件上传
本文网址:http://azwzsj.com/article/pdoihe.html