由于未知错误

时间:2017-05-11 06:24:19

标签: php laravel-5

我正在尝试为多个学生上传相同的图片。它适用于第一个,但对于下一个,它会给出错误。 我的代码

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.

什么是错的..?谢谢。

1 个答案:

答案 0 :(得分:0)

$file = Input::file('attachment');

了解$ file是对象类型:

Illuminate\Http\UploadedFile

它指向服务器上的文件,例如

e‌‌cho $file->getRealPath(); // ‌/tmp/phpp6HYIk

然后您可以通过执行以下操作看到该信息:

$file->move($dest_path);

您正在将文件从其原始目标位置移开,从而使其无法用于后续迭代。