Php 在Laravel 5.1中处理多个文件(作为API)
所以这似乎是一件非常基本的事情,但我在网上找不到很多关于发生了什么的文档 我正在尝试使用Laravel5.1浏览文件列表,我只能返回/处理/查看第一个文件。我正在使用Postman将请求发送到API(因此我知道在Php 在Laravel 5.1中处理多个文件(作为API),php,laravel-5.1,Php,Laravel 5.1,所以这似乎是一件非常基本的事情,但我在网上找不到很多关于发生了什么的文档 我正在尝试使用Laravel5.1浏览文件列表,我只能返回/处理/查看第一个文件。我正在使用Postman将请求发送到API(因此我知道在POST请求中启用了multiple),然后以几种不同的方式重复执行该请求: public function files(Request $request) { foreach($request->files as $file) { var_dump
POST
请求中启用了multiple
),然后以几种不同的方式重复执行该请求:
public function files(Request $request)
{
foreach($request->files as $file)
{
var_dump($file);
}
}
甚至:
我总是返回(如果使用了$request->files
方法,则返回对象窗体):
为什么会这样?如何才能在Laravel 5.1的控制器中查看多个文件?因此,我用以下代码创建了一个全新的页面,名为
files.php
,现在它将返回所有三个文件(或者无论我上传了多少):
现在返回:
array (size=3)
0 =>
object(Symfony\Component\HttpFoundation\File\UploadedFile)[84]
private 'test' => boolean false
private 'originalName' => string 'Screen Shot 2015-10-23 at 10.07.23 AM.png' (length=41)
private 'mimeType' => string 'image/png' (length=9)
private 'size' => int 270504
private 'error' => int 0
private 'pathName' (SplFileInfo) => string '/tmp/php1M5ZJl' (length=14)
private 'fileName' (SplFileInfo) => string 'php1M5ZJl' (length=9)
1 =>
object(Symfony\Component\HttpFoundation\File\UploadedFile)[85]
private 'test' => boolean false
private 'originalName' => string 'Screen Shot 2015-10-26 at 7.28.59 PM.png' (length=40)
private 'mimeType' => string 'image/png' (length=9)
private 'size' => int 13687
private 'error' => int 0
private 'pathName' (SplFileInfo) => string '/tmp/phpE22ubf' (length=14)
private 'fileName' (SplFileInfo) => string 'phpE22ubf' (length=9)
2 =>
object(Symfony\Component\HttpFoundation\File\UploadedFile)[86]
private 'test' => boolean false
private 'originalName' => string 'Screen Shot 2015-10-27 at 2.50.58 PM.png' (length=40)
private 'mimeType' => string 'image/png' (length=9)
private 'size' => int 786350
private 'error' => int 0
private 'pathName' (SplFileInfo) => string '/tmp/phph8v0C8' (length=14)
private 'fileName' (SplFileInfo) => string 'phph8v0C8' (length=9)
希望这对别人有帮助
string 'Screen%20Shot%202015-10-23%20at%2010.07.23%20AM.png' (length=51)
string 'image/png' (length=9)
string '/tmp/phpZw1ALu' (length=14)
int 0
int 13687
<!DOCTYPE>
<html>
<body>
<form method="post" enctype="multipart/form-data" action="http://lucolo.dev/files">
<input type="file" name="files[]" multiple>
<input type="submit" value="Upload">
</form>
</body>
</html>
public function files(Request $request)
{
foreach($request->files as $file)
{
var_dump($file);
}
}
array (size=3)
0 =>
object(Symfony\Component\HttpFoundation\File\UploadedFile)[84]
private 'test' => boolean false
private 'originalName' => string 'Screen Shot 2015-10-23 at 10.07.23 AM.png' (length=41)
private 'mimeType' => string 'image/png' (length=9)
private 'size' => int 270504
private 'error' => int 0
private 'pathName' (SplFileInfo) => string '/tmp/php1M5ZJl' (length=14)
private 'fileName' (SplFileInfo) => string 'php1M5ZJl' (length=9)
1 =>
object(Symfony\Component\HttpFoundation\File\UploadedFile)[85]
private 'test' => boolean false
private 'originalName' => string 'Screen Shot 2015-10-26 at 7.28.59 PM.png' (length=40)
private 'mimeType' => string 'image/png' (length=9)
private 'size' => int 13687
private 'error' => int 0
private 'pathName' (SplFileInfo) => string '/tmp/phpE22ubf' (length=14)
private 'fileName' (SplFileInfo) => string 'phpE22ubf' (length=9)
2 =>
object(Symfony\Component\HttpFoundation\File\UploadedFile)[86]
private 'test' => boolean false
private 'originalName' => string 'Screen Shot 2015-10-27 at 2.50.58 PM.png' (length=40)
private 'mimeType' => string 'image/png' (length=9)
private 'size' => int 786350
private 'error' => int 0
private 'pathName' (SplFileInfo) => string '/tmp/phph8v0C8' (length=14)
private 'fileName' (SplFileInfo) => string 'phph8v0C8' (length=9)