~catch-drupal/+junk/pressflow-content-cache-variable

« back to all changes in this revision

Viewing changes to includes/file.inc

  • Committer: David Strauss
  • Date: 2010-06-18 17:01:06 UTC
  • mfrom: (82.1.2 merge-drupal-6.17)
  • Revision ID: david@fourkitchens.com-20100618170106-eveqf9sepqonszf9
Drupal 6.17 (via testing branch)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
 
// $Id: file.inc,v 1.121.2.11 2010/03/01 09:51:16 goba Exp $
 
2
// $Id: file.inc,v 1.121.2.12 2010/05/11 09:49:58 goba Exp $
3
3
 
4
4
/**
5
5
 * @file
233
233
}
234
234
 
235
235
/**
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.
 
237
 *
 
238
 * This is a powerful function that in many ways performs like an advanced
 
239
 * version of copy().
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.
242
244
 *
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
 
245
 * @param $source
 
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
245
249
 *   success.
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.
 
250
 * @param $dest
 
251
 *   A string containing the directory $source should be copied to. If this
 
252
 *   value is omitted, Drupal's 'files' directory will be used.
 
253
 * @param $replace
 
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
 
257
 *     unique.
 
258
 *   - FILE_EXISTS_ERROR: Do nothing and return FALSE.
 
259
 * @return
 
260
 *   TRUE for success, FALSE for failure.
253
261
 */
254
262
function file_copy(&$source, $dest = 0, $replace = FILE_EXISTS_RENAME) {
255
263
  $dest = file_create_path($dest);
349
357
 
350
358
/**
351
359
 * Moves a file to a new location.
 
360
 *
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.
356
365
 *
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
 
366
 * @param $source
 
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
359
370
 *   success.
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.
 
371
 * @param $dest
 
372
 *   A string containing the directory $source should be copied to. If this
 
373
 *   value is omitted, Drupal's 'files' directory will be used.
 
374
 * @param $replace
 
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
 
378
 *     unique.
 
379
 *   - FILE_EXISTS_ERROR: Do nothing and return FALSE.
 
380
 * @return
 
381
 *   TRUE for success, FALSE for failure.
367
382
 */
368
383
function file_move(&$source, $dest = 0, $replace = FILE_EXISTS_RENAME) {
369
384
  $path_original = is_object($source) ? $source->filepath : $source;
596
611
    }
597
612
 
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';