我的表单样式是这样的

Index/index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<form action="__URL__/upload" method="post">
<table border="1" width="500">
<tr><td>标题</td><td><input type="text" name="title" value="" /></td></tr>
<tr><td><input type='file' name='photo'></td><td><input type="submit" value="上传图片" /></td></tr>
<tr><td>关键词</td><td><input type="text" name="keyword" value="" /></td></tr>
<tr><td>描述</td><td><textarea type="textarea" name="description"></textarea></td></tr>
<tr><td>信息</td><td><input type="text" name="info" /></td></tr>
<tr><td>摘要</td><td><input type="text" name="zhaiyao" /></td></tr>
<tr><td cols=2><input type="submit" name="提交" name="submit" /></td><td></td></tr>
</table>
</form><?php
// 本类由系统自动生成,仅供测试用途
class IndexAction extends Action {
public function index(){
$this->display();
}
Public function upload(){
import('ORG.Net.UploadFile');
$upload = new UploadFile();// 实例化上传类
$upload->maxSize = 3145728 ;// 设置附件上传大小
$upload->allowExts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
$upload->savePath = './Public/Uploads/';// 设置附件上传目录
$upload->saveRule = date('ymdHis',time()).'_'.mt_rand().$info[0]['extension'];//上传文件的保存规则
$upload->uploadReplace = false;//存在同名文件是否是覆盖
$upload->thumbRemoveOrigin = false; //生成缩略图后是否删除原图
$upload->thumb = true; //是否需要对图片文件进行缩略图处理,默认为false
$upload->thumbMaxWidth = '180'; //上传最大宽度
$upload->thumbMaxHeight = '150'; //上传最大高度
$upload->thumbPrefix = 'm_'; //文件前缀
$User->photo = date('ym',time()).'_'.mt_rand().'.'.$info[0]['extension'];
$User->savepath =$info[0]['savepath'].$User->photo;
$User->title = I('title');
$User->keyword = I('keyword');
$User->description = I('description');
$User->info = I('info');
$User->zhaiyao =I('zhaiyao');
$data = $User->add(); // 写入用户数据到数据库
$this->success('数据保存成功!');
}
}
最佳答案