Reputation: 276
I've implemented successfully in my app some of the Laravel file management functionalities : upload, download, move. At least I would've said it is successful cause it works fine until I find out I'm getting issues when storing files with some special characters in their filename/path.
In my case I've remarked it with the colon character. There are other characters which can trigger that. I can successfully register a form with a file input: I mean without those characters, I can without any problem upload, download and edit. But once I get a colon for example in my filename, an input field which is used for the path: ($filename = $request->input('inputFileName') .'.'. $file->getClientOriginalExtension();
$path = $file->storeAs('folder',$filename);
) I get problem.
First, the filename isn't anymore well recorded: from the colon, the remaining of the filename is not registered. For example, let's say the input for the filename is a:b
; in my folder I'll get a
registered instead and without the extension. No need to say this makes me get the File not found at path
error.. when wanting to download. I get that error too when I want to change that filename with a colon to an other. Another thing I remark with the editing too is the fact that I can't rename a file without those characters (colon here) to one with it. When doing so I get the php: Warning: rename The filename, directory name, or volume label syntax is incorrect. (code: 123)
. I've looked for it and found this. It seems to be related to the OS file system. I'm on Windows 10 OS using Laravel 5.8.
Have anyone of you already faced this issue and how did you manage with this? Does Laravel got something to deal with this?.. Any help or suggestion will be very appreciated
Upvotes: 0
Views: 1513
Reputation: 17205
Dont save the files with their original name, just generate a random name to save the file and keep the original name (if needed) in your database or event in another file beside the saved file. Never trust client side inputs.
Upvotes: 2