嗨,我正在尝试将xlsx文件上传到laravel api(我可以上传(图像,xls)文件),但是我无法这样做,因此我得到以下详细信息,< / p>
请求我的标题具有Content-Type作为multipart / form-data
对$file = request()->file('user_bulk_upload'); var_dump($file);
的响应
object(Illuminate\Http\UploadedFile)[424]
private 'test' (Symfony\Component\HttpFoundation\File\UploadedFile) => boolean false
private 'originalName' (Symfony\Component\HttpFoundation\File\UploadedFile) => string 'sudo1.xlsx' (length=10)
private 'mimeType' (Symfony\Component\HttpFoundation\File\UploadedFile) => string 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' (length=65)
private 'error' (Symfony\Component\HttpFoundation\File\UploadedFile) => int 0
protected 'hashName' => string 'jFWNUFGJVuAMNi8p9BdzuZmKXu2MA5RtiOpopBPO' (length=40)
private 'pathName' (SplFileInfo) => string 'C:\xampp\tmp\php2472.tmp' (length=24)
private 'fileName' (SplFileInfo) => string 'php2472.tmp' (length=11)
和$path = $file->store('excel', 'public');var_dump($path);
我得到的回应是
'excel/jFWNUFGJVuAMNi8p9BdzuZmKXu2MA5RtiOpopBPO.bin' (length=50)
有人可以帮我吗?
答案 0 :(得分:1)
我通过以下用于多次上传的功能解决了这个问题:
public static function uploadFiles(int $ticketId, array $files)
{
$dir = self::documentsDir($ticketId);
/** @var Illuminate\Http\UploadedFile $file */
foreach ($files as $file) {
$fileName = \Carbon\Carbon::now()->format('Ymd')."-".strtotime(\Carbon\Carbon::now()).".".$file->getClientOriginalExtension();
$file->storeAs($dir, $fileName, ['disk' => 'public']);
}
}