Summer Sale! All accounts are 50% off this week.

untymage's avatar

UploadedFile::fake() creates folder rather than file

How to work UploadedFile::fake() in none-http context ?

I want to create a fake mp3 file but laravel create a folder:

Storage::fake('public');

UploadedFile::fake()->create('test.mp3', 100)->store('test.mp3', ['disk' => 'public']);

Storage::disk('public')->assertExists('test.mp3');

It create test.mp3 as folder but i excepted this to be a file...

Another issue, The file inside the folder has 0 byte of size, But i excepted 100, What is wrong ?

How can i store test.mp3 under public dir ?

0 likes
3 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

The first parameter of ->store() is the path. It makes a random name automatically. Use ->storeAs('path', 'test.mp3') if you want to specify the filename

1 like
untymage's avatar

@Sinnbeck ty, Another thing, The file has 0 byte filesize but i set it to 100, What i missing ?

Sinnbeck's avatar

@untymage I dont know if it works when you store it as well. Maybe if you move it. I have never needed it as my test should never move the file anywhere.

Please or to participate in this conversation.