Skip to content

Commit

Permalink
Update FileUploadTrait
Browse files Browse the repository at this point in the history
  • Loading branch information
KarolisNarkevicius authored Nov 30, 2017
1 parent 28cc3b7 commit 73eed77
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/Controllers/publish/FileUploadTrait
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ trait FileUploadTrait
mkdir(public_path('uploads'), 0777);
mkdir(public_path('uploads/thumb'), 0777);
}
$newRequest = null; // Variable to hold a new request created by above array merging
foreach ($request->all() as $key => $value) {
if ($request->hasFile($key)) {
if ($request->has($key . '_w') && $request->has($key . '_h')) {
Expand All @@ -39,15 +40,21 @@ trait FileUploadTrait
});
}
$image->save(public_path('uploads') . '/' . $filename);
$request = new Request(array_merge($request->all(), [$key => $filename]));
// Determine which request's data to use further
$requestDataToMerge = $newRequest == null ? $request->all() : $newRequest->all();
// Create new request without changing the original one (prevents removal of specific metadata which disables parsing of a second file)
$newRequest = new Request(array_merge($requestDataToMerge, [$key => $filename]));
} else {
$filename = time() . '-' . $request->file($key)->getClientOriginalName();
$request->file($key)->move(public_path('uploads'), $filename);
$request = new Request(array_merge($request->all(), [$key => $filename]));
// Determine which request's data to use further
$requestDataToMerge = $newRequest == null ? $request->all() : $newRequest->all();
// Create new request without changing the original one (prevents removal of specific metadata which disables parsing of a second file)
$newRequest = new Request(array_merge($requestDataToMerge, [$key => $filename]));
}
}
}

return $request;
return $newRequest == null ? $request : $newRequest;
}
}
}

0 comments on commit 73eed77

Please sign in to comment.