How to upload image with original name and time I want to upload my images with the original name with time of upload
This is my upload code
if($request->hasFile('image'))
{
$image = $request->file('image');
$fileName = $request->image->getClientOriginalName();
$location = public_path('images/' . $fileName);
Image::make($image)->resize(500, 400)->save($location);
$article->image = $fileName;
//$article->image = $request->filename;
}
I want to have something like
most-popular-image-2-7-2018-24-23.jpg
The original name is first then followed by the date and time
you could get away with:
if($request->hasFile('image'))
{
$image = $request->file('image');
$ext = '.'.$request->image->getClientOriginalExtension();
$fileName = str_replace($ext, date('d-m-Y-H-i') . $ext, $request->image->getClientOriginalName());
$location = public_path('images/' . $fileName);
Image::make($image)->resize(500, 400)->save($location);
$article->image = $fileName;
//$article->image = $request->filename;
}
This way you'll replace the current extension with the date + current extension.
The only thing it would have problems with is files named like 'filename.jpg.jpg'
@lostdreamer_nl
Yes I got 'The image failed to upload.' when I tried uploading 'filename.jpg.jpg
I guess there is no fix for that?
wtf? Trying to add a comment gives me a security message saying 'something' I did blocked me for security.... it could be some phrase I posted.....
Let's try in smaller blocks to see which one gives the error:
There's always a fix
I can't post code anymore :S
Sorry about that......
Please sign in or create an account to participate in this conversation.