236
* Copies a file to a new location. This is a powerful function that in many ways
237
* performs like an advanced version of copy().
236
* Copies a file to a new location.
238
* This is a powerful function that in many ways performs like an advanced
238
240
* - Checks if $source and $dest are valid and readable/writable.
239
241
* - Performs a file copy if $source is not equal to $dest.
240
242
* - If file already exists in $dest either the call will error out, replace the
241
243
* file or rename the file based on the $replace parameter.
243
* @param $source A string specifying the file location of the original file.
244
* This parameter will contain the resulting destination filename in case of
246
* Either a string specifying the file location of the original file or an
247
* object containing a 'filepath' property. This parameter is passed by
248
* reference and will contain the resulting destination filename in case of
246
* @param $dest A string containing the directory $source should be copied to.
247
* If this value is omitted, Drupal's 'files' directory will be used.
248
* @param $replace Replace behavior when the destination file already exists.
249
* - FILE_EXISTS_REPLACE - Replace the existing file
250
* - FILE_EXISTS_RENAME - Append _{incrementing number} until the filename is unique
251
* - FILE_EXISTS_ERROR - Do nothing and return FALSE.
252
* @return True for success, FALSE for failure.
251
* A string containing the directory $source should be copied to. If this
252
* value is omitted, Drupal's 'files' directory will be used.
254
* Replace behavior when the destination file already exists.
255
* - FILE_EXISTS_REPLACE: Replace the existing file.
256
* - FILE_EXISTS_RENAME: Append _{incrementing number} until the filename is
258
* - FILE_EXISTS_ERROR: Do nothing and return FALSE.
260
* TRUE for success, FALSE for failure.
254
262
function file_copy(&$source, $dest = 0, $replace = FILE_EXISTS_RENAME) {
255
263
$dest = file_create_path($dest);
351
359
* Moves a file to a new location.
352
361
* - Checks if $source and $dest are valid and readable/writable.
353
362
* - Performs a file move if $source is not equal to $dest.
354
363
* - If file already exists in $dest either the call will error out, replace the
355
364
* file or rename the file based on the $replace parameter.
357
* @param $source A string specifying the file location of the original file.
358
* This parameter will contain the resulting destination filename in case of
367
* Either a string specifying the file location of the original file or an
368
* object containing a 'filepath' property. This parameter is passed by
369
* reference and will contain the resulting destination filename in case of
360
* @param $dest A string containing the directory $source should be copied to.
361
* If this value is omitted, Drupal's 'files' directory will be used.
362
* @param $replace Replace behavior when the destination file already exists.
363
* - FILE_EXISTS_REPLACE - Replace the existing file
364
* - FILE_EXISTS_RENAME - Append _{incrementing number} until the filename is unique
365
* - FILE_EXISTS_ERROR - Do nothing and return FALSE.
366
* @return True for success, FALSE for failure.
372
* A string containing the directory $source should be copied to. If this
373
* value is omitted, Drupal's 'files' directory will be used.
375
* Replace behavior when the destination file already exists.
376
* - FILE_EXISTS_REPLACE: Replace the existing file.
377
* - FILE_EXISTS_RENAME: Append _{incrementing number} until the filename is
379
* - FILE_EXISTS_ERROR: Do nothing and return FALSE.
381
* TRUE for success, FALSE for failure.
368
383
function file_move(&$source, $dest = 0, $replace = FILE_EXISTS_RENAME) {
369
384
$path_original = is_object($source) ? $source->filepath : $source;
598
613
// Rename potentially executable files, to help prevent exploits.
599
if (preg_match('/\.(php|pl|py|cgi|asp|js)$/i', $file->filename) && (substr($file->filename, -4) != '.txt')) {
614
if (preg_match('/\.(php|pl|py|cgi|asp|js)$/i', $file->filename) && (substr($file->filename, -4) != '.txt')) {
600
615
$file->filemime = 'text/plain';
601
616
$file->filepath .= '.txt';
602
617
$file->filename .= '.txt';