Fake a file upload with defined mimetype

Posted 5 months ago by Zini


I want to fake the upload of multiple types. It works for images, but I have a hard time finding out how to simulate other types of files.

Any not-image file gets inode/x-empty for mimetype, where I would like to see application/pdf.

// Mimetype ok
$file = \Illuminate\Http\UploadedFile::fake()->image('test.jpg');

// Mimetype issue: inode/x-empty
$file = \Illuminate\Http\UploadedFile::fake()->create('test.pdf');

// also tried this
$file->mimeType = 'application/pdf';

I did not find yet any solution in the Illuminate doc, or the Symfony doc.

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.