多个上传laravel同名

时间:2017-01-29 10:55:40

标签: php laravel

我已经为laravel上传图片的编辑器创建了新代码。 我使用带有循环的laravel方法,所以如果我选择2个图像,它会上传第一个两次。

我该如何解决?

我想我需要清除输入:)

public function ajax_editor_image() {
    if (Input::file()) {
        $image = Input::file('image');
        $filename = time() . '.' . $image->getClientOriginalExtension();
        $path = public_path('uploads/' . $filename);
        // Image::make($image->getRealPath())->resize(200, 200)->save($path);
        Input::file('image')->move('uploads/', $filename);
        $base_url = URL::to('/');;
        return response()->json([
            'data' => [
                "id"          => "",
                "title"       => null,
                "description" => null,
                "datetime"    => 1462962209,
                "type"        => "image/jpeg",
                "animated"    => false,
                "width"       => 720,
                "height"      => 960,
                "size"        => 108627,
                "views"       => 0,
                "bandwidth"   => 0,
                "vote"        => null,
                "favorite"    => false,
                "nsfw"        => null,
                "section"     => null,
                "account_url" => null,
                "account_id"  => 0,
                "in_gallery"  => false,
                "deletehash"  => "NYoWYJZkpdFyahb",
                "name"        => "",
                "link"        => $base_url . '/uploads/' . $filename,
                "success"     => true,
                "status"      => 200
            ]
        ]);
    }
}

1 个答案:

答案 0 :(得分:1)

将此名称作为图像名称

$filename  = time() .'-'.$image->getClientOriginalName().'.' . $image->getClientOriginalExtension();

我也有同样的问题。有时它会同时上传,你的文件名也一样。因此,通过为图像添加名称,它肯定是唯一的。

我认为这会有所帮助。