⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

GROCERYCRUD - rename file when uploading



manushimn
  • profile picture
  • Member

Posted 15 June 2014 - 13:53 PM

I want to change the file name when uploading. I tried to do this by callbacks. But didn't work any of them.

Method 1 - using callback_before_upload

function callback1($files_to_upload,$field_info)
{
    foreach($files_to_upload as $value) {
        $value['name']='pp.pdf';
    }
}

 

 

Method 2 - using callback_after_upload

function callback2($uploader_response,$field_info, $files_to_upload)
{
     foreach($files_to_upload as $value) {
          $uploader_response[0]->name='pp.pdf';
     }
     return true;
}

 

Method1 ddnt work at all. In method2, file name at database changed to pp.pdf, but uploaded file in upload directory ddnt change at all. So my question is how to rename the file when uploading. Can anyone please help me?

 


Amit Shah
  • profile picture
  • Member

Posted 16 June 2014 - 05:26 AM

well.. u have to change the name of the file that u uploaded .. it wont automatically set the name.. So you just need to add the code to change the name of the file uploaded and thats it - u done with it..

 

Happy GCing:)