简体   繁体   English

Laravel 文件上传或移动带有特殊字符的问题

[英]Laravel file upload or move issue with special characters

I've implemented successfully in my app some of the Laravel file management functionalities: upload, download, move.我已经在我的应用程序中成功实现了一些 Laravel 文件管理功能:上传、下载、移动。 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.但是一旦我在我的文件名中得到一个冒号,一个用于路径的输入字段:( $filename = $request->input('inputFileName').'.'. $file->getClientOriginalExtension(); $path = $file->storeAs('folder',$filename); ) 我遇到了问题。

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 ;例如,假设文件名的输入是a:b in my folder I'll get a registered instead and without the extension.在我的文件夹中,我将获得a注册而不是扩展名。 No need to say this makes me get the File not found at path error.. when wanting to download.不用说这让我File not found at path ..想要下载时。 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)这样做时,我得到php: Warning: rename The filename, directory name, or volume label syntax is incorrect. (code: 123) php: Warning: rename The filename, directory name, or volume label syntax is incorrect. (code: 123) . 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.我在使用 Laravel 5.8 的 Windows 10 操作系统上。

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 Laravel 是否有办法解决这个问题?.. 任何帮助或建议将不胜感激

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.永远不要相信客户端的输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM