Answer the question
In order to leave comments, you need to log in
Duplicate protection in Laravel images?
There is a need to create protection against copying images, namely, so that it is impossible to upload the same picture twice.
What can be used as a key? Trite md5 hash pictures? And will it help if you rename the picture, change the extension?
I also look in the direction of determining the degree of similarity of the pictures, but I doubt something.
Answer the question
In order to leave comments, you need to log in
> And will it help if you rename the picture, change the extension?
If the file name was not taken into account when generating the hash sum, then it will help.
www.stackoverflow.com/a/5055152
To generate a temporary link to an image, write a helper, accept a link to the image in the function and save it in the session. Example:
namespace App\Helpers;
trait ProtectedImage {
static function url($image, $path = 'images/'){
$hash = md5(time() . $image . 'somestring');
session(['image.'.$hash => $image]);
return $hash;
}
}
Route::get('images/{filename}', function ($filename)
{
$realfilename = session('image.'.$filename);
if(empty($realfilename)) abort(404);
$path = storage_path() . '/' . $realfilename;
$file = File::get($path);
$type = File::mimeType($path);
$response = Response::make($file, 200);
$response->header("Content-Type", $type);
return $response;
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question