我有这个输入
<input type="file" name="photos[]">
for($j=0; $j < count($files['infos']); $j++){
$photo[$j] = $files->file('photos[]');
if (count($photo[$j]) > 0) {
$file_storage = Storage::disk('local')->put('images/photos', $photo[$j], 'public');
}
}
之后我收到了这个错误
file_put_contents(在/ usr /本地/网络/ doc_test /公共/图片/照片): 无法打开流:是一个目录
修改
var_dump($photo[$j])
array(2) { [0]=> object(Illuminate\Http\UploadedFile)#378 (8) { ["test":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> bool(false) ["originalName":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> string(11) "1-slide.png" ["mimeType":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> string(9) "image/png" ["size":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> int(716589) ["error":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> int(0) ["hashName":protected]=> NULL ["pathName":"SplFileInfo":private]=> string(14) "/tmp/phpdqpVKO" ["fileName":"SplFileInfo":private]=> string(9) "phpdqpVKO" } [1]=> object(Illuminate\Http\UploadedFile)#386 (8) { ["test":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> bool(false) ["originalName":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> string(11) "4-slide.png" ["mimeType":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> string(9) "image/png" ["size":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> int(1699553) ["error":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> int(0) ["hashName":protected]=> NULL ["pathName":"SplFileInfo":private]=> string(14) "/tmp/phphhvZUI" ["fileName":"SplFileInfo":private]=> string(9) "phphhvZUI" } }
答案 0 :(得分:0)
我不知道您的刀片是什么样的,但您可以将其用于文件上传:
{{ Form::open(array('files'=>'true', 'action' => 'Controller@upload') ) }}
{{ Form::file('photos[], ['multiple' => 'multiple']);
{{ Form::submit('upload') }}
{{ Form::close() }}
您的控制器方法'upload'应包含以下内容:
public function upload( Request $request ) {
$this->validate( request(), [
'file' => 'required'
]);
foreach ( $request->photos as $photo ) {
// use whatever u need
dump( $photo );
}
}
请记住,您需要使用文件名存储...
查看此网站:http://laraveldaily.com/upload-multiple-files-laravel-5-4/
答案 1 :(得分:0)
for($j=0; $j < count($files['infos']); $j++){
$photo[$j] = $files->file('photos[]');
if (count($photo[$j]) > 0) {
$file_storage = Storage::disk('local')->put('images/photos/'.str_random(6).'.jpg', $photo[$j], 'public');
}
}