求教如何将上传图片的路径保存到数据库。

浏览:4583 发布日期:2015/07/08 分类:求助交流
我要上传缩略图,发布商品要用到form表单,上传图片也要用到form表单,那么我上传成功的图片路径改如何保存到数据库呢?<form method="post" action="{:U('addpeijie')}">
<div style="margin:50px 250px;line-height:50px;">
名称:<input type="text" name="name" style="width:200px;"/><br>
价格:<input type="text" name="price" style="width:500px;"/><br>
数量:<input type="text" name="count" style="width:50px;"/><br>
有效期至:<input type="text" name="validity" style="width:50px;"/><br>
地点:<select name="place">
<option value="长沙">长沙</option>
<option value="株洲">株洲</option>
</select><br>
适用于:<input type="text" name="applytype" style="width:50px;"/><br>
类型:<select name="pid">
<volist name="list" id="vo">
<option value="{$vo.id}">{$vo.name}</option>
</volist>
</select><br>
<input type="submit" value="发布" />
</div>
</form>

<form action="__URL__/upload" enctype="multipart/form-data" method="post" >
缩略图:
<input type="text" name="name" value=""/>
<input type="file" name="photo" />
<input type="submit" value="提交" ><br>
</form>
      
      //上传图片
      public function upload(){
          $upload = new \Think\Upload();// 实例化上传类
          $upload->maxSize   =     3145728 ;// 设置附件上传大小
          $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
          $upload->rootPath  =     './Upload/parts/'; // 设置附件上传根目录
          $upload->savePath  =     ''; // 设置附件上传(子)目录
          // 上传文件
          $info   =   $upload->upload();
          if(!$info) {// 上传错误提示错误信息
              $this->error($upload->getError());
          }else{// 上传成功
              $this->success('上传成功!');
          }
      }
最佳答案
评论( 相关
后面还有条评论,点击查看>>