流明文件上传

0 php api file laravel lumen

我有以下代码用于文件上传:

$picName = $request->file('cnicFrontUrl')->getClientOriginalName();
$picName = Carbon::now() . $picName;
$destinationPath = '/uploads/user_files/cnic';
$request->file('cnicFrontUrl')->move($destinationPath, $picName);
Run Code Online (Sandbox Code Playgroud)

在我的公用文件夹中uploads/user_files/cnic

我收到的异常:

{
  "message": "Could not move the file \"D:\\xampp\\tmp\\php2D1C.tmp\" to \"uploads/user_files/cnic\\2017-05-22 09:06:15cars.png\" ()",
  "status_code": 500
}
Run Code Online (Sandbox Code Playgroud)

这里缺少什么?

Dha*_*lia 5

尝试这个

        $picName = $request->file('image')->getClientOriginalName();
        $picName = uniqid() . '_' . $picName;
        $path = 'uploads' . DIRECTORY_SEPARATOR . 'user_files' . DIRECTORY_SEPARATOR . 'cnic' . DIRECTORY_SEPARATOR;
        $destinationPath = public_path($path); // upload path
        File::makeDirectory($destinationPath, 0777, true, true);
        $request->file('image')->move($destinationPath, $picName);
Run Code Online (Sandbox Code Playgroud)

我们不能这样设置文件名

2017-05-22 09:06:15cars.png

因此,请使用uniqid()函数获取图像的唯一文件名