$destination = file_create_path() . '/imagecache/'. $preset .'/'. $path;
- // Generate a unique file name in the drupal temp directory
- $tmpdestination = tempnam(file_directory_temp(), basename($path));
+ // prepend presetname to tmp file name to prevent namespace clashes when
+ // multiple presets for the same image are called in rapid succession.
+ $tmpdestination = file_directory_temp() . '/' . $preset . str_replace(dirname($path) . '/', '', $path);
$dir = dirname($destination);
//drupal_set_message('$tmpdestination: '. $tmpdestination);
return;
}
- // Check if the finished file has been written to disk since the webserver looked for it
- if (!is_file($destination)) {
+ //check if file exists to prevent multiple apache children from trying to generate.
+ if (!is_file($tmpdestination)) {
$generated = TRUE;
- file_copy($source, $tmpdestination, FILE_EXISTS_REPLACE);
+ file_copy($source, $tmpdestination);
foreach($actions as $action) {
$size = getimagesize($tmpdestination);
}
}
file_move($tmpdestination, $destination);
- }
- else {
+ } else {
$generated = TRUE;
}
if (function_exists('mime_content_type')) {
$mime = mime_content_type($destination);
}
- else {
- $size = getimagesize($destination);
- $mime = $size['mime'];
- }
- file_transfer($destination, array('Content-Type: ' . mime_header_encode($mime), 'Content-Length: ' . filesize($destination)));
+ else {
+ $size = getimagesize($destination);
+ $mime = $size['mime'];
+ }
+ file_transfer($destination, array('Content-Type: ' . mime_header_encode($mime), 'Content-Length: ' . filesize($destination)));
}
else {
// Generate an error if image could not generate.