thinkphp上传文件出错。怎么办呢?没找到问题所在。
thinkphp吧
全部回复
仅看楼主
level 1
wide288 楼主
模板:
addProduct.html
------------------------------
<script language="JavaScript">
<!--
    function add(){
        ThinkAjax.sendForm('form1','__URL__/insertProduct',complete,'result');
    }
    function complete(data,status){
        if (status==1)
        {
        window.setTimeout(function (){window.location.href='__URL__/listProduct',20000});
        }
    }
//-->
</script>
<div class="main">
<h2>产品添加</h2>
    <form id="form1" method='post' action="__URL__/insertProduct" enctype="multipart/form-data">
<table cellpadding=2 cel
lsp
acing=2>
<tr>
    <td colspan="2"><div id="result" class="none result" style="font-family:微软雅黑,Tahoma;letter-spacing:2px"></div></td>
</tr>
<tr>
......
...
...
<tr>
    <td class="tRight" width="12%">图片:</td>
    <td class="tLeft" ><input type="file" name="photo" style="height:23px" class="huge bLeft"> </td>
</tr>
<tr>
    <td><input type="hidden" name="ajax" value="1"></td>
    <td><input type="button" onClick="add()" class="button" value="保 存"> <input type="reset" class="button" value="清 空"></td>
</tr>
</table>
   </form>
------------------------------------------------------------------
控制器
---------------------------
public function insertProduct() {
      if (!empty($_FILES)) {
  
         //如果有文件上传 上传附件
          $this->_upload();
  
         //$this->forward();
      }
   
}
    // 文件上传
  
protected function _upload() {
      import("@.ORG.UploadFile");
    
   $upload = new UploadFile();
  
    //设置上传文件大小
       $upload->maxSize = 3292200;
     //设置上传文件类型
   
    $upload->allowExts = explode(',', 'jpg,gif,png,jpeg');
       //设置附件上传目录
  
     $upload->savePath = '../Public/Uploads/';
       //设置需要生成缩略图,仅对图像文件有效

2010年12月01日 07点12分 1
level 1
wide288 楼主

      $upload->thumb = true;
      // 设置引用图片类库包路径
        $upload->imageClassPath = '@.ORG.Image';
       //设置需要生成缩略图的文件后缀
       $upload->thumbPrefix = 'm_,s_';
//生产2张缩略图
       //设置缩略图最大宽度
  
     $upload->thumbMaxWidth = '400,100';
   
    //设置缩略图最大高度
   
    $upload->thumbMaxHeight = '400,100';
       //设置上传文件规则
  
     $upload->saveRule = uniqid;
   
    //删除原图
    
   $upload->thumbRemoveOrigin = true;
      if (!$upload->upload()) {
   
        //捕获上传异常
       
    $this->error($upload->getErrorMsg());
     
} else {
   
        //取得成功上传的文件信息
     
      $uploadList = $upload->getUploadFileInfo();
    
       import("@.ORG.Image");
     
      //给m_缩略图添加水印, Image::water('原文件名','水印图片地址')
     
      Image::water($uploadList[0]['savepath'].'m_'.$uploadList[0]['savename'], '../Public/Images/logo2.png');
          $_POST['image'] = $uploadList[0]['savename'];
       }
      $model = M('Photo');
      //保存当前数据对象
      $data['image'] = $_POST['image'];
      $data['create_time'] = time();
      $list = $model->add($data);
        if ($list !== false) {
  
         $this->success('上传图片成功!');
  
     } else {
          $this->error('上传图片失败!');
      }
   }
2010年12月01日 07点12分 2
level 1
wide288 楼主
Ajax 不能上传文件,已经解决。
2010年12月01日 16点12分 3
level 1
支持一下。。
2011年01月31日 04点01分 5
1