Remove time() string from filenames in Laravel when showing


Remove time() string from filenames in Laravel when showing



I am using time() function to add time string to the file names like this and storing them in the database


$filename = time() . $file->getClientOriginalName();



But How Can I remove this string when I show the files to the user and when the user downloads the file.
I am using Laravel by the way.




1 Answer
1



The timestamp is 10 digits I believe, so doing:


substr($filename,10):



Would trim it from the beginning of the filename. When downloading a file, you can give the file name which is displayed/suggested to the user like this:


return response()->download($filename, substr($filename, 0, 10), $headers);





substr($filename, 0, 10): this has removed the file name except the time() string but using this substr($filename, 10) has solved my problem. and I wanna ask how could I make users download the file. I mean how to use the above response you described.
– Mohan Sharma
Jun 29 at 10:55





Hah, yeah that is backwards. The download method should trigger the browser to prompt the user for confirmation.
– DigitalDrifter
Jun 29 at 10:57





I am using 'download' attribute of HTML's <a> tag to download the file and adding the file path in href attribute. Is this the wrong way of making the browser to download the file instead of opening. Or is there any other way to do that.
– Mohan Sharma
Jun 29 at 11:02






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

how to run turtle graphics in Colaboratory

Export result set on Dbeaver to CSV