--- drupal-4.6.0/includes/file.inc 2005-04-15 13:37:22.205239400 -0700 +++ file.inc 2005-04-15 13:36:59.676664264 -0700 @@ -17,12 +17,42 @@ define('FILE_DOWNLOADS_PRIVATE', 2); define('FILE_CREATE_DIRECTORY', 1); define('FILE_MODIFY_PERMISSIONS', 2); -define('FILE_DIRECTORY_TEMP', IS_WINDOWS ? 'c:\\windows\\temp' : '/tmp'); +define('FILE_DIRECTORY_TEMP', IS_WINDOWS ? 'c:\\windows\\temp' : getcwd().'/tmp'); define('FILE_EXISTS_RENAME', 0); define('FILE_EXISTS_REPLACE', 1); define('FILE_EXISTS_ERROR', 2); /** + * Wrapper to get around open_basedir restriction. Function is idempotent: + * multiple calls have the same effect as one (1). In order to function, + * FILE_DIRECTORY_TEMP must not be restricted by open_basedir directive. + * times has + * + * @param $source The Object representation of the uploaded file. + * @return $file On success, returns the Object representaiont of the + * relocated file; on failure, the original $source parameter is returned. + */ +function file_relocate($source) { + //$tmp_base = variable_get('file_directory_temp', FILE_DIRECTORY_TEMP); + $tmp_base = getcwd().'/'; + $tmp_local = 'tmp/'; + if(move_uploaded_file( + $source->filepath, + $tmp_base.$tmp_local.$source->filename) + ){ + $file = new StdClass(); + $file->filename = $source->filename; + $file->filemime = $source->filemime; + $file->filepath = $tmp_local.$source->filename; + $file->error = $source->error; + $file->filesize = $source->filesize; + $file->source = $source->source; + $file->list = 1; + return $file; + } + return $source; +} +/** * Create the download path to a file. * * @param $path Path to the file to generate URL for @@ -128,9 +158,14 @@ */ function file_check_upload($source) { if (is_object($source)) { + $source = file_relocate($source); if (is_file($source->filepath)) { return $source; } + else { + // XXX Here is a potential source of a problem! There is nothing + // returned in this case. + } } elseif ($_FILES["edit"]["name"][$source] && is_uploaded_file($_FILES["edit"]["tmp_name"][$source])) { $file = new StdClass(); @@ -205,7 +240,7 @@ // Process a file upload object. if (is_object($source)) { - $file = $source; + $file = file_relocate($source); $source = $file->filepath; if (!$basename) { $basename = $file->filename; @@ -214,8 +249,12 @@ $source = realpath($source); if (!file_exists($source)) { - drupal_set_message(t('File copy failed: source file does not exist.'), 'error'); - return 0; + // XXX + if(!move_uploaded_file($source,$dest)) { + drupal_set_message(t('File copy failed: source file does not exist.'), 'error'); + return 0; + } + return 1; } // If destination file is not specified then use filename of source file. @@ -291,6 +330,9 @@ */ function file_move(&$source, $dest = 0, $replace = FILE_EXISTS_RENAME) { + if(is_object($source)) { + $source = file_relocate($source); + } $path_original = is_object($source) ? $source->filepath : $source; if (file_copy($source, $dest, $replace)) { @@ -368,10 +410,14 @@ case 0: // UPLOAD_ERR_OK break; case 1: // UPLOAD_ERR_INI_SIZE + drupal_set_message(t('File upload failed: UPLOAD_ERR_INI_SIZE.'), 'error'); + return 0; case 2: // UPLOAD_ERR_FORM_SIZE drupal_set_message(t('File upload failed: file size too big.'), 'error'); return 0; case 3: // UPLOAD_ERR_PARTIAL + drupal_set_message(t('File upload failed: UPLOAD_ERR_PARTIAL.'), 'error'); + return 0; case 4: // UPLOAD_ERR_NO_FILE drupal_set_message(t('File upload failed: incomplete upload.'), 'error'); return 0; @@ -389,6 +435,9 @@ } return 0; } + else { + drupal_set_message(t('File upload failed: file_check_upload() failed.'), 'error'); + } return 0; }