Modification in drupal for making filefield works. This info was posted in http://drupal.org/node/313539 too. Please refer it for complete info.
Title: Compatiblity with FileField: private_upload cannot work with filefield without modification of code.
...
I finally found the problem.
It is because in Private_upload.module the hook of download. If I change "return -1" to "return", then it works perfectly for the files uploaded by CCK-filefield into the priavte area (directory). Of course, this is not a solusion since all the attached file will not have access control at all.
With a little more code tracking, I realized that there is no information related to filefield upload in the Database, if I upload files with CCK-filefield. Therefore, with
$result = db_query("SELECT DISTINCT(u.nid) FROM {upload} u INNER JOIN {files} f ON u.fid = f.fid ".
"WHERE f.filepath = '%s'", $filepath);
$result will be empty and hence all the downloading is blocked no matter who is the user (even admin).
With this conclusion, private upload cannot work with filefield without modification of code. Since paivate file attachment is not importatn to me, to have access control for file of the filefield. My solusion right now is disable private upload and:
1) Put an .htaccess in a private directory to give access control to Drupal.
2) Use filefield_path to set private directory of the protected filefield so that the upload files of the protected filefield go to the private direcotry.
If anyone thinks something wrong about the solusion, please let me know.
hosais
============================
The hock of file download() in private upload module.
============================
function private_upload_file_download($file) {
$private_dir = variable_get('private_upload_path', 'private');
if(_private_upload_starts_with($file, $private_dir)) {
$filepath = file_create_path($file);
$result = db_query("SELECT DISTINCT(u.nid) FROM {upload} u INNER JOIN {files} f ON u.fid = f.fid ".
"WHERE f.filepath = '%s'", $filepath);
while($row = db_fetch_array($result)) {
$node = node_load($row['nid']);
if (node_access('view', $node)) {
return; // Access is ok as far as we are concerned.
}
}
return -1; // No nodes are granting access, so veto download. <--- CHANGE THIS to return;
}
}
Don't add to the db directly