写一个form表单。里面有两个不会写:(1)图片的上传(2)select下拉框值的上传。
现在的问题是这样的:我想上传图片,并将图片的路径传到数据库,为了在另外一个页面要显示图片的地方能够获取到数据库的内容。select下拉框有几个值,想提交到数据库好像有点bug用正常的$_POST["select的name"] 似乎有点问题。求大神指教!有没有完整一点的form表单提交demo,只要求有上传图片、select下拉框并且在数据库提取数据显示在前台页面的代码。急!找了半天资料到是看到了提交和创建文件夹路径,但是怎么写进数据库那段不会。
<!--<form enctype="multipart/form-data" action="" method="post" name="theForm">-->
<!-- <table width="90%" align="center" style="display: table;" id="general-table">-->
<!-- <tbody>-->
<!-- <tr>-->
<!-- <td class="label">商品分类:</td>-->
<!-- <td>-->
<!-- <select name="cate_id">-->
<!-- <option value="0">请选择...</option>-->
<!-- <foreach name="cate" item="val">-->
<!-- <option value="{$val.cate_id}" path="{$val.path}">{:str_repeat(" ",substr_count($val['path'],'-')-1)}{$val.cate_name}</option>-->
<!-- </foreach>-->
<!-- </select>-->
<!-- </td>-->
<!-- </tr>-->
<!-- <tr>-->
<!-- <td class="label">上传商品图片:</td>-->
<!-- <td>-->
<!-- <input type="file" size="35" name="goods_img">-->
<!-- <a target="_blank" href=""><img border="0" src="__PUBLIC__/Admin/images/yes.gif"></a>-->
<!-- </td>-->
<!-- </tr>-->
<!-- </tbody>-->
<!-- </table>-->
<!-- <div class="button-div">-->
<!-- <input type="submit" value=" 确定 " class="button" onclick="validate('32')">-->
<!-- <input type="reset" value=" 重置 " class="button">-->
<!-- </div>-->
<!-- <input type="hidden" name="act" value="update">-->
<!--</form>-->
$upload = new \Think\Upload();// 实例化上传类
$upload->maxSize = 3145728 ;// 设置附件上传大小
$upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
$upload->rootPath = './public/images/'; // 设置附件上传根目录
$upload->savePath = ''; // 设置附件上传(子)目录
$upload->saveName = 'time';
$upload->saveExt='jpg';
$upload->autoSub='false';
// 上传文件
$info = $upload->upload();
foreach($info as $file){
$filename=$file['savepath'].$file['savename'];
}
$username=session('user');
session('imgs',"/thinkphp_table/public/images/".$filename);
$where=array('user_name'=>$username);
$member=M('member');
$add=array('member_img'=>$filename);
$row=$member->where($where)->save($add);
图片的上传,可以上传图片的名称,不一定要src,然后在你的编辑器里面新建一个文件夹,放入你的图片,可以用字符串拼接的方式显示。