php - How to rename more than 1 file during upload ? Codeigniter -
i have form upload 5 files, lets photo of person registering , other document him.
now i'm creating folder every registered user name ( btw, thing do? ), , want rename each file right name let photo,document a,document b , etc.
my current code
$upload_setting['upload_path'] = './uploads/'.$_post['name'].'/'; $upload_setting['allowed_types'] = 'jpg|pdf'; $upload_setting['max_size'] = 5000; // 5 mb $upload_setting['file_name'] = $_post['name']; // define uploaded file name $this->load->library('upload', $upload_setting); if ($this->form_validation->run() == false){ $this->load->view('form'); } else{ if (!is_dir('./uploads/'.$_post['name'].'/')) { mkdir('./uploads/'.$_post['name'].'/', 0777, true); } $this->member->register($this->input->post(null, true)); $this->upload->do_upload('photo'); $this->upload->do_upload('document-a'); $this->upload->do_upload('document-b');
also how can let them free upload jpg,pdf,doc ? have link these file in profile page. how can know extension upload each document ?
please let me know if have suggestion or best practice upload , display each upload in profile.
thanks
to know extension of file can use-
$newname= "name"; $path_parts = pathinfo($_files["picture"]["name"]); $file_newname = $newname.'.'.$path_parts['extension'];
to upload-
if( $_files['picture']['name'] ) { $config['upload_path'] = 'images/receipt/'; $config['allowed_types'] = 'gif|jpg|jpeg|png'; $config['file_name'] = $file_newname; //here file being renamed $this->load->library('upload', $config); if ( ! $this->upload->do_upload('picture')) { $error = array('error' => $this->upload->display_errors()); return false; } }
Comments
Post a Comment