php - 使用 laravel 将文件夹上传到服务器
问题描述
我正在尝试编写一个允许用户上传文件夹的脚本。基本上用户会指定一个文件夹,所有包含的文件都应该上传,在服务器上重建相对路径或文件夹结构。
html 部分使用webkitdirectory
,
<form action="cmd/test" enctype="multipart/form-data" method="post">
<input id="upload" name="content[]" type="file" value="Input" directory webkitdirectory>
<input type="submit" value="submit">
</form>
服务器是用 Laravel 编写的。我希望Request
在 Laravel 中使用,比如
Route::any('cmd/test', function(\Illuminate\Http\Request $request) {
echo $request;
$files = $request->file('content');
echo json_encode($files);
//Store the files here...
});
我尝试上传一个测试文件夹,内容如下:
dir /s test
Directory of C:\Users\███████\Desktop\test
18-Nov-18 05:19 PM <DIR> .
18-Nov-18 05:19 PM <DIR> ..
18-Nov-18 05:19 PM 1 note1.txt
18-Nov-18 05:19 PM 1 note2.txt
18-Nov-18 05:20 PM <DIR> test1
2 File(s) 2 bytes
Directory of C:\Users\███████\Desktop\test\test1
18-Nov-18 05:20 PM <DIR> .
18-Nov-18 05:20 PM <DIR> ..
18-Nov-18 05:20 PM 1 note3.txt
1 File(s) 1 bytes
Total Files Listed:
3 File(s) 3 bytes
令我惊讶的是,测试脚本的输出是
[{},{},{}]
使用 不会检索有关文件名或内容的信息Request::file()
。Edge 或 Firefox 的结果相同。有什么建议么?
编辑:基本上我没有意识到返回值的类型是UploadedFile
. 获取文件的相对路径以重建文件夹结构的问题仍然存在。
解决方案
推荐阅读
- audio - 优化 ffmpeg 覆盖和循环过滤器
- c++ - Visual Studio 尝试链接静态库的嵌套库依赖项
- python - Python manage.py migrate 不创建表
- java - 在 hadoop yarn 上运行 pyspark 无法连接到 localhost/127.0.0.1:46311
- netsuite - nlapiSearchRecord 中的 If Else 语句
- oracle-jet - 如何在 OJET Table 中设置无限滚动?
- ubuntu - ubuntu 18.04 中的 Lumen 虚拟主机
- javascript - vuejs - 在列表 B 中存在项目时检查列表 A 中的循环标记
- python - 使用 mplfinance 创建烛台图的问题
- c++ - QAudioRecorder 为什么不通过构造函数录制?