douyan2002
2017-11-23 20:23
浏览 40
已采纳

Codeigniter使用不同的区域名称进行多次上传,并在上传之前重命名该文件

I have a problem with multiple files upload with different area name and want to change for every area filename before it's upload.

This is HTML form.

<input type="file" placeholder="" name="profilPic"/>
<input type="file" placeholder="" name="topPic"/>

This is controller

    $config['upload_path']          = './uploads/';
    $config['allowed_types']        = 'gif|jpg|png';
    $config['max_size']             = 100;
    $config['max_width']            = 1024;
    $config['max_height']           = 768;
    //$config['file_name']          = $this->session->sersession["id"];
    $this->load->library('upload', $config);
    $profilPic = $this->upload->do_upload('profilPic');
    if (!$profilPic){
        $error = array('error' => $this->upload->display_errors());
        $this->session->set_flashdata("error", "profil pic was not uploaded= ");
    }else{
        $data = array('upload_data' => $this->upload->data());
        $this->session->set_flashdata("success", "profil picture was uploaded.");
    }
    $topPic = $this->upload->do_upload('topPic');
    if (!$topPic){
            $error = array('error' => $this->upload->display_errors());
            $this->session->set_flashdata("error", "top pic was not uploaded" );

    }else{
        $data = array('upload_data' => $this->upload->data());
        $this->session->set_flashdata("success", "this picture was uploaded.");
    }

Note: The pictures are upload to directory. But i want to rename every file file name before uploaded like "userID_profil.jpg" and "userID_top.jpg"

图片转代码服务由CSDN问答提供 功能建议

我在上传多个文件时遇到问题,上传的区域名称不同,并希望在上传之前更改每个区域文件名。

这是HTML表单。

 &lt; input type =“file”placeholder =“”name =“profilPic”/&gt; 
&lt; input type =“file”placeholder =“”name =“  topPic“/&gt; 
   
 
 

这是控制器

  $ config ['upload_path'] ='./  uploads''; 
 $ config ['allowed_types'] ='gif | jpg | png'; 
 $ config ['max_size'] = 100; 
 $ config ['max_width'] = 1024; 
 $ config  ['max_height'] = 768; 
 // $ config ['file_name'] = $ this-&gt; session-&gt; sersession [“id”]; 
 $ this-&gt; load-&gt; library('  upload',$ config); 
 $ profilPic = $ this-&gt; upload-&gt; do_upload('profilPic'); 
 if(!$ profilPic){
 $ error = array('error'=&gt;  $ this-&gt; upload-&gt; display_errors()); 
 $ this-&gt; session-&gt; set_flashdata(“error”,“profil pic not uploaded =”); 
} else {
 $ data  = array('upload_data'=&gt; $ this-&gt; upload-&gt; data()); 
 $ this-&gt; session-&gt; set_flashdata(“成功”,“profil图片已上传。”); \  n} 
  $ topPic = $ this-&gt; upload-&gt; do_upload('topPic'); 
 if(!$ topPic){
 $ error = array('error'=&gt;  $ this-&gt; upload-&gt; display_errors()); 
 $ this-&gt; session-&gt; set_flashdata(“error”,“top pic not a uploaded”); 
 
} else {
 $  data = array('upload_data'=&gt; $ this-&gt; upload-&gt; data()); 
 $ this-&gt; session-&gt; set_flashdata(“success”,“此图片已上传。”);  
} 
   
 
 

注意:图片会上传到目录。 但我想在上传之前重命名每个文件名,如“userID_profil.jpg”和“userID_top.jpg”

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题