--- private_upload.module.orig 2008-10-17 08:34:28.000000000 -0500 +++ private_upload.module 2008-10-17 08:46:15.000000000 -0500 @@ -228,13 +228,20 @@ function private_upload_nodeapi(&$node, $fid = $file->fid; // for the cases where we have temp fid for uploaded files $success = false; $filepath = $file->filepath; // need copy if file_move fails. + // save original name + $filepath_orig = $filepath; $public = file_directory_path(); $private_path = _private_upload_path(); // actual path of private files $file_is_private = _private_upload_is_file_private($filepath); if( $file->private && !$file_is_private ) { // private flag is set, but file NOT yet listed as being in private repo, // so try and move it from public area to private repo - if( file_move($filepath, $private_path, FILE_EXISTS_REPLACE) ) { + if( file_move($filepath, $private_path, FILE_EXISTS_RENAME) ) { + // check whether the file was renamed + if ($filepath_orig != $filepath) { + // update the filename in the object if so + $file->filename = basename($filepath); + } $success = true; } else { @@ -244,7 +251,12 @@ function private_upload_nodeapi(&$node, else if (!$file->private && $file_is_private) { // private flag is false, but file IS g in private repo // so try and move it from private repo to public area - if (file_move($filepath, $public, FILE_EXISTS_REPLACE)) { + if (file_move($filepath, $public, FILE_EXISTS_RENAME)) { + // check whether the file was renamed + if ($filepath_orig != $filepath) { + // update the filename in the object if so + $file->filename = basename($filepath); + } $success = true; } else { @@ -253,8 +265,8 @@ function private_upload_nodeapi(&$node, } if( $success ) { // we were able to move the file, so update filepath in db. - db_query("UPDATE {files} SET filepath = '%s' WHERE fid=%d AND nid=%d", - $filepath, $fid, $node->nid); + db_query("UPDATE {files} SET filepath = '%s', filename = '%s' WHERE fid=%d AND nid=%d", + $filepath, $file->filename, $fid, $node->nid); $row_count = db_affected_rows(); if( $row_count != 1 ) { drupal_set_message( "Error: Unable to make uploaded file private! (". $row_count .")", 'error' ); @@ -525,9 +537,15 @@ function _private_upload_migrate_private while( $file = db_fetch_object($result) ) { // file is attached to a private node, but is a public file, so move it. $filepath = $file->filepath; - if( file_move($filepath, $private_path, FILE_EXISTS_REPLACE) ) { + $filepath_orig = $filepath; + if( file_move($filepath, $private_path, FILE_EXISTS_RENAME) ) { + // check whether the file was renamed + if ($filepath_orig != $filepath) { + // update the filename in the object if so + $file->filename = basename($filepath); + } $output .= t("Making !filename private", array('!filename'=>$file->filename)). "
"; - db_query("UPDATE {files} SET filepath = '%s' WHERE fid=%d AND nid=%d", $filepath, $file->fid, $file->nid); + db_query("UPDATE {files} SET filepath = '%s', filename = '%s' WHERE fid=%d AND nid=%d", $filepath, $file->filename, $file->fid, $file->nid); } else { $output .= t("Could not move %filepath to private directory (fid: %fid attached to node: nid).",