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
]
]);
}
}
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.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments