问题
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