0

I faced an issue that in /uploads appear files with name like 69398f524b17741a34ee3f77234797e2.jpg etc. It seems that file is encoded as random MD5.

In library Upload.php I found that MD5 used for adding an number to end file name if it found that file with equal name already exist.

In model I have such code:

 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
  • just make $config['encrypt_name'] = TRUE; to false or don't use it in config by default it is false
    – umefarooq
    Jul 16, 2013 at 6:40

1 Answer 1

1

Intead of $config['encrypt_name'] = TRUE; write $config['encrypt_name'] = FALSE;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.