How can I remove empty spaces form a file name when uploading to the server

Posted 2 years ago by fsdolphin

Hi,

How can I remove empty spaces form a file name when uploading to the server?

Here is the code I'm currently using which grabs the file's original name and saves it into hard disc (storage/app/images).

$file = request()->file('imageFile');
$fileName =  $file->getClientOriginalName();
$file->storeAs('images/', $fileName);

I know I could use the following code which automatically generates a hash name but I need to capture the name to be able to save it in a database and I'm not sure if using this method would be possible to get the auto generated hash name.

request()->file('imageFile')->store('images');

Again, how can I remove any empty space form a file?

For instance, change my file name.jpg to myfilename.jpg

Thanks

Please sign in or create an account to participate in this conversation.