I have drupal installed in a subdir (/drupal) and backup files unable to locate the directories specified for backup. I managed to get it to work by changing line 157 from $rp = realpath('.'. $bp. trim($dir)); to $rp = realpath(trim($dir));

CommentFileSizeAuthor
#4 backup_files.patch1.33 KBdavidjany
#2 backup_files.patch777 bytesmikeytown2

Comments

RickA99’s picture

I have Drupal 6.9 installed in a sub-directory and I tried the code fix above and got the same error message as before, "Does not exist: /sites/all/themes/" until I added a period in front of the backup directory path.

"Test Settings" didn't work: /sites/all/modules

"Test Settings" worked: ./sites/all/modules

Unfortunately, when I tried to do an actual backup, the file that got downloaded was empty.

Error message:

warning: filesize() [function.filesize]: stat failed for /backup.tgz in /[my-path]/sites/all/modules/backup_files/backup_files.module on line 216.
warning: fopen(/backup.tgz) [function.fopen]: failed to open stream: No such file or directory in /[my-path]//sites/all/modules/backup_files/backup_files.module on line 220.

function backup_files_download($filename, $filetype, $file_path) {
header('Content-Type: '. $filetype);
header('Expires: '. gmdate('D, d M Y H:i:s') .' GMT');
header('Content-Length: '. filesize($file_path)); <--------------line 216
header('Content-Disposition: attachment; filename="'. $filename .'"');

// Transfer file in 1024 byte chunks to save memory usage.
if ($fd = fopen($file_path, 'rb')) { <--------------line 220
while (!feof($fd)) {
print fread($fd, 1024);
}
fclose($fd);
}

module_invoke_all('exit');
exit();
}

mikeytown2’s picture

StatusFileSize
new777 bytes
mikeytown2’s picture

Status: Active » Needs review
davidjany’s picture

StatusFileSize
new1.33 KB

With minor changings and a existing and writable tmp-dir it's working for me in a subdir.

Thx.

jhodgdon’s picture

Just a note that this patch doesn't work for me, although I have the same issue. The module is not finding the files, or looking in the correct location. I'm on a LAMP server with Drupal installed (for the moment) in a subdirectory.

jhodgdon’s picture

Status: Needs review » Needs work

So I'm marking this as "needs work", because this patch evidently doesn't solve the problem generally enough.

jhodgdon’s picture

The problem is that base_path() (which is used in this function) returns the base *url*, not the base file path. You can't really make assumptions about how to derive a path from this -- it is very dependent on the web server, Drupal installation, etc.

You need to instead do something like what conf_path() does, or better yet just use conf_path(). If the module is meant to only backup files within the sites/whatever/files directory, then file_directory_path() will give you a path to that directory.

sinasquax’s picture

For me this patch works :

On backup_files.module, replace in line 155 :

$rp = realpath('.'. $bp. trim($dir));

by :

$rp = realpath('./' . trim($dir));

And replace in line 172 :

$bfn = realpath('.'. $bp. $temp). '/backup.tgz';

by :

$bfn = realpath('./' . $temp). '/backup.tgz';

And you can remove line 131 too.

It works with drupal installed in sub directory and in root directory