0

I've created new code for editor to upload image by laravel. I use a laravel method with a loop, so if I selecetd 2 images it's upload the first one twice.

How can I solve it?

I think I need to clear Input :)

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 Answer 1

1

Try this name as image name

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

I also had the same problem . sometimes it will upload at same time and your file name would be same. so by adding name to the image also it would be definitely unique.

I think it will help.

Sign up to request clarification or add additional context in comments.

1 Comment

Glad to help @AhmedNaguib :). This is a generic problem and accept and up vote this answer so that it would be helpful for others

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.