php - Returning each file path into an array? -
i have upload function in controller takes multiple file uploads. far uploads files directory want capture each 1 array
.
how go doing this?
here code
$files = request::file('document'); foreach($files $file) { $rules = array( 'file' => 'required|mimes:png,gif,jpeg,txt,pdf,doc,docx,rtf|max:20000' ); $validator = \validator::make(array('file'=> $file), $rules); if($validator->passes()){ $destinationpath = '/public/uploads/'; $mime_type = $file->getmimetype(); $extension = $file->getclientoriginalextension(); $filename = str_random(12) . '.' . $extension; $upload_success = $file->move($destinationpath, $filename); } else { return redirect::back()->with('error', 'we accept png,gif,jpeg,txt,pdf,doc,rtf.'); // add error here. } }
when validator passes processes each 1 when add variable $path = $upload_success;
takes last 1 processed. how can capture array of file paths processed $path
?
before foreach
, create array $paths = [];
after $upload_success
var created, add array. $paths[] = $upload_success;
now $paths
array of paths.
Comments
Post a Comment