Setting the name of a file saved through a filefield

只愿长相守 提交于 2019-12-25 08:15:14

问题


I have a form that allows users to upload a resume through a form.

The submit method saves the data into CareerApplication with the resume attached as a has_one relation.

$submission = new CareerApplication();
$form->saveInto($submission);

I would like to control the filename the resume is saved as.

How can i set the filename of the uploaded file?


回答1:


You could try this

$up = new Upload();

$file = Object::create('File');

$file->setFileName('newname');

$up->loadIntoFile($data['FileName'], $file, 'Uploads/Files');

if($up->isError()) {
    //handle error here
    //var_dump($up->getErrors());
}else {
      //file uploaded
      $file->ID;            
}           


来源:https://stackoverflow.com/questions/22930368/setting-the-name-of-a-file-saved-through-a-filefield

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!