简体   繁体   English

Windows 10中的文件上传权限Laravel

[英]File upload permissions Laravel in Windows 10

I tried uploading a file with the following code in ubuntu 我尝试在ubuntu中使用以下代码上传文件

$file = $request->file('file_upload');
$destination = app_path() . '/myStorage/';
$fileName = $sampleName . '-' . date('Y-m-d-H:i:s') . '.' . $file->getClientOriginalExtension();
$file->move($destination, $fileName);

and it worked fine. 而且效果很好。 Now i am trying to run the same code in Windows OS and i am getting the following error 现在,我试图在Windows OS中运行相同的代码,但出现以下错误

Could not move the file "C:\\wamp64\\tmp\\php6570.tmp" to "C:\\wamp64\\www\\gittest\\gittest\\IBA\\app\\myStorage\\Test-2016-02-17-10:43:27.xlsx" () 无法将文件“ C:\\ wamp64 \\ tmp \\ php6570.tmp”移动到“ C:\\ wamp64 \\ www \\ gittest \\ gittest \\ IBA \\ app \\ myStorage \\ Test-2016-02-17-10:43:27。 xlsx“()

Is there any problem in the code or is there a permission issue? 代码中是否有任何问题或权限问题? Please help me. 请帮我。

The filename contains ':' which are not allowed on windows in file names. 文件名包含“:”,在Windows中文件名中不允许使用。 That is the reason probably you are getting the error. 这就是您可能会收到错误的原因。
Try 尝试

$filename = $sampleName . '-' . date('Y-m-d-H_i_s') . '.' . $file->getClientOriginalExtension();  

Should be able to save the file then. 然后应该可以保存文件了。
Basically replace the ':' (colon) in the date(format) with any thing which is allowed as filename on windows. 基本上将date(format)中的':'(冒号)替换为Windows上允许作为文件名的任何内容。 Even a space would be ok like: 甚至一个空格也可以:

$filename = $sampleName . '-' .date('Y-m-d H i s') . '.' . $file->getClientOriginalExtension();  
Or
$filename = $sampleName . '-'.date('Y-m-d g i A').'.' . $file->getClientOriginalExtension(); //ex output Test-2016-02-18 11 25 AM.xls

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

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