【发布时间】:2019-04-18 02:14:22
【问题描述】:
我正在尝试为多个学生上传同一张图片。它适用于第一个,但对于下一个它会出错。 我的代码
foreach($student_ids as $key => $student_id) {
$fileIds='';
if(Input::hasfile('attachment')){
$comment = $comments[0];
$file = Input::file('attachment');
$destinationPath = public_path().'/uploads/moments/'.$student_id;
$filename = "moment_".time()."_".trim(rand(1,999)).".".$file->getClientOriginalExtension();
if(is_dir($destinationPath)) {
$upload_success = $file->move($destinationPath, $filename);
}else {
if(mkdir($destinationPath)) {
$upload_success = $file->move($destinationPath, $filename);
}
}
$file = Moment_gallery::create(['image'=>$filename,'comment'=>$comment]);
$fileIds.=$file->id.',';
}
$moments = new moment();
$moments->activity_id = $activity;
$moments->type=$activity_type;
$moments->student_id=$student_id;
$moments->date = $date;
$moments->time = $activity_time ? $activity_time : ' ';
$moments->save();
}
在这里,我正在获取多个学生 ID 的数组...所以我只是为这些学生上传相同的图像。它适用于单个学生,但随后适用于多个学生,它适用于第一个学生并为第二个学生提供错误
FileException in UploadedFile.php line 235:The file "student.png" was not uploaded due to an unknown error.
怎么了..?谢谢。
【问题讨论】: