Level 35
Use str_slug() on the filename. Not the filename including the extension otherwise the dot will be replaced with a dash see https://laravel.com/docs/5.6/helpers#method-str-slug
2 likes
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
User can upload images for their post & the image name may contain spaces. So while seeing this in front end, the spaces are replaced by %20 which shows invalid propery value.
So my question is, how can I save the image in database without spaces or the spaces replaced with any character (for eg.: hyphen or underscore) .
Below is my controller, saving images
if ($request->hasFile('logoimg')) {
$logoimgwithExt = $request->file('logoimg')->getClientOriginalName();
$logoimgFileName = pathinfo($logoimgwithExt, PATHINFO_FILENAME);
$extension = $request->file('logoimg')->getClientOriginalExtension();
$logoFileNameToStore = $logoimgFileName.'_'.time().'.'.$extension;
$path = $request->file('logoimg')->storeAs('public/logo_images',$logoFileNameToStore);
} else {
$logoFileNameToStore = 'no-logo.jpg';
}
Use str_slug() on the filename. Not the filename including the extension otherwise the dot will be replaced with a dash see https://laravel.com/docs/5.6/helpers#method-str-slug
Please or to participate in this conversation.