0

I'm trying to upload pictures with personalized names. If somebody uploads a picture to some project, I want this personalized name: Project_imageX.jpg, where X is the number of the image. This number is controlled with a counter in my code, but it doesn't matter.

I read about the parameters that the function do_upload() supports, so, I tried to do something like this:

$this->upload->do_upload('form_name',$my_name); 

the variable $my_name is filled with the structure specified before. But it doesn't work.

Do you know what I'm doing wrong?

Thak you all!

6
  • 1
    do_upload() only takes one parameter. You want to edit the file_name value in the $config array before you call $this->upload->initialize. See: ellislab.com/codeigniter/user-guide/libraries/… Commented Mar 31, 2014 at 15:49
  • That is something I read too. So, I have to change the upload config everytime that someody uploads an image? Commented Mar 31, 2014 at 15:52
  • Or just simply rename it after it's uploaded. rename($data['full_path'], $data['file_path'].$new_name); Commented Mar 31, 2014 at 15:52
  • if i rename it, will change the name of the FTP file? I'm totally newbie with uploading files in Codeigniter Commented Mar 31, 2014 at 15:54
  • What do you mean "the FTP file"? CodeIgniter just wraps around PHP's native file upload functions (like move_uploaded_file()). So, it just puts the file on your server. If you rename it, it'll be renamed. FTP is just another way to access the files. Commented Mar 31, 2014 at 15:55

1 Answer 1

1

Code Igniter's file upload class accepts the file_name parameter to specify the name of the file being uploaded (file_name - If set CodeIgniter will rename the uploaded file to this name. The extension provided in the file name must also be an allowed file type - re: http://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html):

    $config['upload_path'] = './uploads/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['file_name']    = '100';
    $config['max_width']  = '1024';

    $config['file_name']  = 'myfile.jpg'; // must include extension and extension must be available in allowed_types

    $this->load->library('upload', $config);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.