Upload multiple files in Laravel 4
Here is my controller code for uploading multiple files and I am passing
key and value from 'postman' rest API client on Google Chrome.I am adding
multiple files from postman but only 1 file is getting upload
Kindly,correct my code or my method to upload multiple files,ASAP. Help is
appreciated.Thank You!!
public function post_files() {
$allowedExts = array("gif", "jpeg", "jpg",
"png","txt","pdf","doc","rtf","docx","xls","xlsx");
foreach(Input::file('file') as key -> $abc)
{
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
$filename= $temp[0];
$destinationPath = 'upload/'.$filename.'.'.$extension;
if(in_array($extension,
$allowedExts)&&($_FILES["file"]["size"] < 20000000))
{
if($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] .
"<br>";
}
if (file_exists($destinationPath))
{
echo $filename." already exists. ";
}
else
{
$uploadSuccess=move_uploaded_file($_FILES["file"]["tmp_name"],$destinationPath);
if( $uploadSuccess )
{
$document_details=Response::json(Author::insert_document_details_Call($filename,$destinationPath));
return $document_details; // or do a
redirect with some message that file was
uploaded
// return Redirect::to('authors')
}
else
{
return Response::json('error', 400);
}
}
}
}
}
No comments:
Post a Comment