Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kwebble's avatar

How to get the folder for temporary files

My application needs to store temporary files.

What is the common folder Laravel uses for temporary files? And is there a system call to retrieve that folder in my code?

0 likes
11 replies
JackD's avatar

you can create your own folder inside public or storage folder for temporary files

kwebble's avatar

I can create my own, but isn't there a default folder for temporary files managed by Laravel?

ohffs's avatar

You can also get the operating systems temp directory using PHP (and make temp files). Eg,

$temp = tempnam(sys_get_temp_dir(), 'myApp_');
print $temp;
// /tmp/myApp_Z104Q.tmp
2 likes
kwebble's avatar

@ohffs : yes, I will use sys_get_temp_dir() if Laravel does not provide a standardized folder.

d3xt3r's avatar

temp files are not managed by laravel, its managed by the web server.

1 like
kwebble's avatar

Sure, files in the system temp folder are managed by the OS.

But because using temporary files is a common feature I hoped Laravel has a common, standardized, solution. Since the folder has to be writable at run-time by the web server, it needs special attention when deploying. Laravel could have something to make sure rights are set correctly.

As it looks now I have to come up with my own solution.

3 likes
laracoft's avatar

@tariqbilal better to start a new discussion and explain what you want to do but can't, followed by what you already tried to fix the problem

Please or to participate in this conversation.