Welcome Guest, Not a member yet? Register   Sign In
Replace file name for upload
#1

[eluser]K-C[/eluser]
I am trying to do a image replacing functionalities using the Upload library, therefore I tried replace the new upload file name before uploading it. How can I do so?
#2

[eluser]xwero[/eluser]
You can set the config option encrypt_name to true and then replace the encrypted file name with your file name
Code:
$config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']    = '100';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';
                $config['encrypt_name'] = true;
        
        $this->load->library('upload', $config);
    
        if ( ! $this->upload->do_upload())
        {
            $error = array('error' => $this->upload->display_errors());
            
            $this->load->view('upload_form', $error);
        }    
        else
        {
            $data = $this->upload->data();
            rename($data['full_path'],$data['file_path'].$_POST['filename'].$data['file_ext']);
            
        }

You should validate your filename if it is posted of course but this is the code that comes closest to renaming a file before uploading.
Using native php functions you just rename the tempfile that is uploaded.
#3

[eluser]wdm*[/eluser]
Why is encrypt_name required?




Theme © iAndrew 2016 - Forum software by © MyBB