Код: Выделить всё
public function upload(Request $request){
$validator = Validator::make($request->all(), [
'file-upload' => 'required',
'file-upload.*' => 'file|mimes:mp3,wav,mp4'
]);
if ($validator->fails()) {
return redirect('/upload-files')
->withErrors($validator)
->withInput();
}
$names = [];
if($request->hasFile('file-upload')) {
foreach ($request->file('file-upload') as $file) {
if(file_exists($file)){
$name= $file->getClientOriginalName();
$names[] = $name;
}
}
}
$api = env('CUSTOMERLYTICS_API').'/v1/upload';
$response = Http::attach(
$names, $request->file('file-upload')
)->post($api, [
'name' => Auth::user()->name.date("Y-m-d H:i:s"),
'company' => Auth::user()->id,
'api' => false,
'language' => 'nl'
]);
//ddd($response->json());
return view('dashboard');
Код: Выделить всё
Http::attach(
$names, $request->file('file-upload')
Код: Выделить всё
/**
* Attach a file to the request.
*
* @param string|array $name
* @param string|resource $contents
* @param string|null $filename
* @param array $headers
* @return $this
*/
public function attach($name, $contents = '', $filename = null, array $headers = [])
{
if (is_array($name)) {
foreach ($name as $file) {
$this->attach(...$file);
}
return $this;
}
$this->asMultipart();
$this->pendingFiles[] = array_filter([
'name' => $name,
'contents' => $contents,
'headers' => $headers,
'filename' => $filename,
]);
return $this;
Как я могу устранить эту ошибку? Или как лучше отправить POST несколько файлов в одном запросе?
Подробнее здесь: https://stackoverflow.com/questions/708 ... post-reque
Мобильная версия