You are here

function _plupload_fix_temporary_filename in Plupload integration 7.2

Same name and namespace in other branches
  1. 8 plupload.module \_plupload_fix_temporary_filename()
  2. 7 plupload.module \_plupload_fix_temporary_filename()
  3. 2.0.x plupload.module \_plupload_fix_temporary_filename()

Fix the temporary filename provided by the plupload library.

Newer versions of the plupload JavaScript library upload temporary files with names that contain the intended final prefix of the uploaded file (e.g., ".jpg" or ".png"). Older versions of the plupload library always use ".tmp" as the temporary file extension.

We prefer the latter behavior, since although the plupload temporary directory where these files live is always expected to be private (and we protect it via .htaccess; see plupload_handle_uploads()), in case it ever isn't we don't want people to be able to upload files with an arbitrary extension into that directory.

This function therefore fixes the plupload temporary filenames so that they will always use a ".tmp" extension.

Parameters

string $filename: The original temporary filename provided by the plupload library.

Return value

string The corrected temporary filename, with a ".tmp" extension replacing the original one.

2 calls to _plupload_fix_temporary_filename()
plupload_element_value in ./plupload.module
Validate callback for plupload form element.
plupload_handle_uploads in ./plupload.module
Callback that handles and saves uploaded files.

File

./plupload.module, line 507
Implementation of plupload.module.

Code

function _plupload_fix_temporary_filename($filename) {
  $pos = strpos($filename, '.');
  if ($pos !== FALSE) {
    $filename = substr_replace($filename, '.tmp', $pos);
  }
  return $filename;
}