文件上传小案例

原创 2018-12-29 17:27:16 147
摘要:<h1>文件上传</h1> <form action="控制上传的脚本文件" method="post" enctype="multipart/form-data"> <input type="file" name="
<h1>文件上传</h1>
<form action="控制上传的脚本文件" method="post" enctype="multipart/form-data">
<input type="file" name="file">
<button>提交</button>
</form>
//处理文件上传
public function demo()
{
    $file = Request::file('file');
    if(is_null($file)){
        $this->error('请选择上传文件');
    }
    	$rule = ['size'=>2097152, 'ext'=>'jpg,jpeg,png,gif','type'=>'image/jpeg,image/png,image/gif'];
		if($file->check($rule)) {
			$fileInfo = $file->move('uploads');
			$res = '<h3 style="color:green;">上传成功</h3>文件名是:'.$fileInfo->getSaveName();		
		} else {
			$res = '<h3 style="color:red;">上传失败</h3>'.$file->getError();	
		}			

		return $res;
}


批改老师:天蓬老师批改时间:2018-12-29 17:39:36
老师总结:你这是有框架了吗?为什么不将代码复制完整?

发布手记

热门词条