Jenz
Jenz

Reputation: 8369

Avoid replacing of space in filename with underscore while uploading

I have a form in Codeigniter in which I am uploading a file. If the file name contains space eg: images (1).jpg then, it is getting uploaded in the secure folder as images_(1).jpg. How to avoid this? I want to upload it with the same name of the image eg: images (1).jpg.

I have used trim() while accessing the file name as:

$thumbfile=trim($_FILES['thumb_image']['name']);

For file uploading, I have used the following section of code :

$config1['upload_path'] = './secure/'.$lastid;
$ext = end(explode(".", $_FILES['thumb_image']['name']));
$config1['file_name'] = trim($_FILES['thumb_image']['name']);
$config1['allowed_types'] = 'jpg|png|jpeg|gif|bmp|jpe|tiff|tif';
$this->load->library('upload', $config1);

Can anyone help me to solve this problem. Thanks in advance.

Upvotes: 2

Views: 3508

Answers (1)

LifeQuery
LifeQuery

Reputation: 3282

Try $config['remove_spaces'] = FALSE;

Otherwise, look in the core upload library where you'll see the $this->file_name = preg_replace("/\s+/", "_", $this->file_name); in the do_upload method which you can alter.

Upvotes: 5

Related Questions