I have a script that checks a zipfile containing a number of matching PDF+textfiles. I want to unpack, or somehow read the textfiles from the zipfile, and just pick out some
The "mkdir" function raises a warning if the directory already exists, so you can catch this using "@mkdir" and avoid any race condition:
function tempDir($parent = null)
{
// Prechecks
if ($parent === null) {
$parent = sys_get_temp_dir();
}
$parent = rtrim($parent, '/');
if (!is_dir($parent) || !is_writeable($parent)) {
throw new Exception(sprintf('Parent directory is not writable: %s', $parent));
}
// Create directory
do {
$directory = $parent . '/' . mt_rand();
$success = @mkdir($directory);
}
while (!$success);
return $directory;
}