I used uniqid () in the past to create a unique file name, but did not actually create the file.
$filename = uniqid(rand(), true) . '.pdf';
The first parameter may be whatever you want, but I used rand () here to make it even more random. Using a dialing prefix, you can avoid collisions with other temp files on the system.
$filename = uniqid('MyApp', true) . '.pdf';
From there, you simply create a file. If all else fails, put it in a while loop and continue to generate it until you get the one that works.
while (true) { $filename = uniqid('MyApp', true) . '.pdf'; if (!file_exists(sys_get_temp_dir() . $filename)) break; }
Lusid Jan 20 '09 at 5:04 2009-01-20 05:04
source share