我有以下控制器,我想上传相同的文件并保存在不同的文件夹中,但我的第二个saveAs()
无效。
$model->profil_picture_file = UploadedFile::getInstance($model,'profil_picture_file');
$model->profil_picture_file->saveAs('path to first folder'); //it works image saved
$model->profil_picture_file->saveAs('path to second folder'); //doesn't work not saved
让我知道我做错了什么?为什么会出错?
提前致谢。
答案 0 :(得分:2)
像这样使用:
$model->profil_picture_file = UploadedFile::getInstance($model,'profil_picture_file');
$model->profil_picture_file->saveAs('path to first folder', false); //set deleteTempFile param to false
$model->profil_picture_file->saveAs('path to second folder'); //it will work now and delete temp file
saveAs()
接受2个参数 - file
和deleteTempFile
答案 1 :(得分:-2)
因为文件saveAs
使用移动文件的move_uploaded_file
,所以第二个saveAs
不起作用,因为文件已经移动了。因此,请使用copy('path to first folder', 'path to second folder')