Hope this could help you.
It works fine under Windows, but I do have troubles with my Mac...
If somebody has a solution 😉))
Pierre
<?
function lock($file) {
$timeout = 30; // Timeout (secondes) PHP
$retry = 5; // Temps maxi (secondes) d'attente avant abandon
$delay = 0.1; // DurÈe d'attente (secondes) entre chaque test
if (file_exists($file.".lck")) {
unlink($file.".lck");
}
for($i = 0; $i < $retry; $i += $delay) {
if (!file_exists($file.".lck")) {
$idlck=@fopen($file.".lck","w");
@fclose($idlck);
return 1;
}
usleep($delay * 1000000);
}
return 0;
}
// -------------------------------------------------------------------------
function unlock($file) {
$i = @unlink($file.".lck");
return $i;
}
// -------------------------------------------------------------------------
function error($msg){
echo $msg;
exit();
}
// -------------------------------------------------------------------------
if (!lock($dir.$file)) error("The file \"$file\" is busy. Try again later!");
unlock($dir.$file);
// fool the http server and client browser into thinking the file name
// passed in is coming back as a application attachment to save as a file
// rather than be rendered
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=$file");
?>