I can't see a field that I can add to help people upload a file. Sure, the node system provides an attachment field by default, but you can't add any instructions to it. This seems an oversight.

Or am I missing something?

Comments

stanbroughl’s picture

dopry is working on the file field at the moment - in the mean time you can use something like node reference to work around it i guess

http://drupal.org/node/50055
http://drupal.org/cck-status

venkat-rk’s picture

Hi, thanks for the answer and for the links:-)

stanbroughl’s picture

that's ok - glad i can help you out for a change lol!

luyendao’s picture

Does anybody know when CCK will be a bit more full-featured like the old flexinode?

I found flexinode very easy to use, in fact i still use it on my 4.7 site, but i know (vaguely) that the way it does table inner joins? is a problem for some reason.

Well keeping in line with wanting to use something that will be used in the future, i'd like to use CCK.

jkopel’s picture

I ran into the missing attachments with cck, and although I am looking forward to the file field (among other things), I needed an immediate solution.
I am using the contemplate module http://drupal.org/project/contemplate, and it gives access to all of the internals of a type.
So in my template I put:

<?php  if (is_array($files) && user_access('view uploaded files')) { ?>
<?php print theme('upload_attachments',$files); ?>
<?php } ?>

Then in my template.php I put a themed version of the theme_upload_attachments function from the upload module (although you could just use it directly).

This seems to work really well, and I can format the list of files differently for different types if I want to.
Hope this helps someone.

jkopel

venkat-rk’s picture

function theme_upload_attachments($files) {
  $header = array(t('Attachment'), t('Size'));
  $rows = array();
  foreach ($files as $file) {
    if ($file->list) {
      $href = check_url(($file->fid ? file_create_url($file->filepath) : url(file_create_filename($file->filename, file_create_path()))));
      $text = check_plain($file->description ? $file->description : $file->filename);
      $rows[] = array(l($text, $href), format_size($file->filesize));
    }
  }
  if (count($rows)) {
    return theme('table', $header, $rows, array('id' => 'attachments'));
  }
}

Is this the code one needs to put in template.php?

jkopel’s picture

You should change the function name to phptemplate_upload_attachments (but you knew that).

I changed mine a bit to get rid of the table, but yes, that is the right stuff.

venkat-rk’s picture

You should change the function name to phptemplate_upload_attachments (but you knew that).

Thank you. I remember reading about it, but I had actually forgotten.

I noticed that dopry had released a filefield module, so I tried it after installing the cvs version of cck which it requires. But, I was hit with all kind of errors such as implode, bad arguments etc, so I gave up.

mtk’s picture

How can I have the CCK filefield to show in a view a link to the uploaded file?

venkat-rk’s picture

I am kind of lost with regard to Views. I dont know if the CCK filefield is a selectable option for building Views.

jkopel’s picture

This is basically the same thing Ramdak was asking...
If you are using contemplate with cck you can make sure that the filefield is included in the type of view you are creating.

For instance in a List View you would:

1. include the node body in your view fields and choose teaser.

2. build the teaser template so that it includes:

<?php  if (is_array($files) && user_access('view uploaded files')) { ?>
<?php print theme('upload_attachments',$files); ?>
<?php } ?>

3. in your theme's template.php you would put:

function phptemplate_upload_attachments($files) {
$header = array(t('Attachment'), t('Size'));
$rows = array();
foreach ($files as $file) {
if ($file->list) {
$href = check_url(($file->fid ? file_create_url($file->filepath) : url(file_create_filename($file->filename, file_create_path()))));
$text = check_plain($file->description ? $file->description : $file->filename);
$rows[] = array(l($text, $href), format_size($file->filesize));
}
}
if (count($rows)) {
return theme('table', $header, $rows, array('id' => 'attachments'));
}
}

A teaser list would be similar, but it ignores fields (I think) so you can skip that step.

If you are not using the contemplate module then you can do the same thing by themeing you view (see http://drupal.org/node/42597).

I have done both, and would strongly suggest starting with the contemplate method until you are very comfortable with themeing and views. Views theming is very powerful, but a bit complicated.

xxparanormalxx’s picture

sub