Codeigniter上传名称长度为32的多个文件

时间:2013-07-16 06:39:02

标签: file codeigniter upload

我遇到一个问题,在/ uploads中出现名称为69398f524b17741a34ee3f​​77234797e2.jpg等的文件。似乎该文件被编码为随机MD5。

在库Upload.php中,我发现MD5用于在结束文件名中添加一个数字,如果它发现具有相同名称的文件已经存在。

在模型中我有这样的代码:

 function do_upload()
   {

     $config['upload_path']     = './uploads/';
     $config['allowed_types']   = 'gif|jpg|png|jpeg';
     $config['max_size']        = '1000';
     $config['max_width']       = '2024';
     $config['max_height']      = '2024';
     $config['encrypt_name'] = TRUE;

    //var_dump($config);

     $this->load->library('upload', $config);

     $temp_files = $_FILES;
    // var_dump($temp_files);
    // echo "files";

    // var_dump($_FILES);

     $count = count ($_FILES['userfile']['name']);

    for ($i=0; $i<=$count-1; $i++){

     $_FILES['file'] = array (
                'name'=>$temp_files['userfile']['name'][$i],
                'type'=>$temp_files['userfile']['type'][$i],
                'tmp_name'=>$temp_files['userfile']['tmp_name'][$i],
                'error'=>$temp_files['userfile']['error'][$i],
                'size'=>$temp_files['userfile']['size'][$i]);
    unset($_FILES['userfile']);         
    var_dump($_FILES);

    if ( ! $this->upload->do_upload('file'))
    {
        $error = array('error' => $this->upload->display_errors());

        $this->load->view('insert', $error);
    }
    else
    {


        $this->upload->do_upload('file');

        $tmp_data = $this->upload->data();
               echo "<hr>";   
         var_dump($tmp_data);   

    }//end else

    }//end for
    }//end do_upload

var_dump($ _ FILES)return

   array (size=1)
         'file' => 
                 array (size=5)
                      'name' => string 'Desert.jpg' (length=10)
                      'type' => string 'image/jpeg' (length=10)
                      'tmp_name' => string 'C:\Windows\Temp\php3776.tmp' (length=27)
                      'error' => int 0
                      'size' => int 845941

var_dump($ tmp_data)return

     array (size=14)
           'file_name' => string '69398f524b17741a34ee3f77234797e2.jpg' (length=36)
           'file_type' => string 'image/jpeg' (length=10)
           'file_path' => string 'D:/server/www/melok/uploads/' (length=28)
           'full_path' => string 'D:/server/www/melok/uploads /69398f524b17741a34ee3f77234797e2.jpg' (length=64)
           'raw_name' => string '69398f524b17741a34ee3f77234797e2' (length=32)
           'orig_name' => string 'Desert.jpg' (length=10)
           'client_name' => string 'Desert.jpg' (length=10)
           'file_ext' => string '.jpg' (length=4)
           'file_size' => float 826.11
          'is_image' => boolean true
          'image_width' => int 1024
          'image_height' => int 768
         'image_type' => string 'jpeg' (length=4)
         'image_size_str' => string 'width="1024" height="768"' (length=25)

1 个答案:

答案 0 :(得分:1)

而不是$config['encrypt_name'] = TRUE;$config['encrypt_name'] = FALSE;