Hi,
This issue might be similar to http://drupal.org/node/651312.
When uploading files using the CCK filefield+SWFupload widget (allows multiple file uploads: http://drupal.org/project/swfupload), I get as many "the selected file /var/www/ cannot be copied" errors as there are attached files. The files are sometimes uploaded to the files folder (at the root) or the link generated will be something like "/sites/defaults/files/C:/users.....". The filefield paths are not created and files are not renamed.

If using regular upload (CCK filefield) then filefieldpaths work ok.
If using the "retroactive update" / "active update" options then folders are created and files are moved/renamed correctly (so I don't think it is a permissions issue).

My best guess is that it has to do with handling the array of submitted files that SWFUpload creates and getting data from it.

Any insight into this error?
Thanks!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Deciphered’s picture

Hi pimousse98,

This looks like an issue with the way that the FileFields are being created in the SWFUpload, there isn't enough data for FileField Paths to operate on. I recall a few issues with other modules doing the same thing (I believe one was jUpload or something similar) where they needed to make a simple change to their code and everything was peachy.

I'm trying to track down those old issues so I can test this theory, and if so I will provide the information and/or a patch to the SWFUpload module.

Cheers,
Deciphered.

Deciphered’s picture

Title: compatibility with SWFUpload module? » Problems with file object (Support for FileField Paths)
Project: File (Field) Paths » SWFUpload
Version: 6.x-1.4 » 6.x-2.0-beta2
Category: support » bug

Moved this issue to SWFUpload.
Also, marked as a bug report as whether or not they'd want to try to support FileField Paths, there are issues that need to be fixed.

So far I have tracked down the issue to a few different area.
The file object defined in swfupload_widget_validate() doesn't supply enough information about the file object, causing issues. The best what to get the correct information is by using field_file_save_file() but due to a few other issues this isn't a perfect solution.

Currently by implementing the following change you will get somewhat working support, but I will go into the other issues in a below:

Change swfupload.module line #141 from:

      $form_state['values'][$element['#field_name']][$key] = array(
        'fid' => $file['fid'],
        'list' => $file['list'],
        'data' => array(
          'description' => $file['description'],
          'alt' => $file['alt'],
          'title' => $file['title'],
        ),
      );

To:

      $form_state['values'][$element['#field_name']][$key] = array_merge(
        field_file_save_file(file_directory_path() . '/' . $file['filename']),
        array(
          'list' => $file['list'],
          'data' => array(
            'description' => $file['description'],
            'alt' => $file['alt'],
            'title' => $file['title'],
          ),
        )
      );

The two issues I have come across are:
1. The swfupload_widget.js is function ref.updateStack() is passing the first (or last?) filename for all the files, so if multiple files are uploaded the above code will rename them all to the same filename_#

2. When the files are being renamed, the numbering is starting at an odd offset (2 files, first number starts at 3), guessing this is related to the files being saved already, and field_file_save_file() is resaving them?

Will try to keep looking into this and come up with a fix.

Cheers,
Deciphered.

Deciphered’s picture

Another option, just to get support for FileField Paths in and pretend the other issues don't exist (not a great approach) is to do the following:

Change swfupload.module line #141 from:

      $form_state['values'][$element['#field_name']][$key] = array(
        'fid' => $file['fid'],
        'list' => $file['list'],
        'data' => array(
          'description' => $file['description'],
          'alt' => $file['alt'],
          'title' => $file['title'],
        ),
      );

To:

      $form_state['values'][$element['#field_name']][$key] = array_merge(
        db_fetch_array(db_query("SELECT * FROM {files} WHERE fid = %d", $file['fid'])),
        array(
          'list' => $file['list'],
          'data' => array(
            'description' => $file['description'],
            'alt' => $file['alt'],
            'title' => $file['title'],
          ),
        )
      );

Cheers,
Deciphered.

pimousse98’s picture

Hi Deciphered,

Thank you so much for looking into this! I will test the solutions that you have outlined and let you know what I find out.
Again, many thanks,

Delphine

pimousse98’s picture

#3 works for me! Many thanks!

smalek’s picture

#3 solution works for me too. Good job! Thanks

smalek’s picture

solution #3 still works, but I had a problem with thumbnails in swfupload filed - thumbnails disappeared. I found that imagefield stores this files (default 32px x 32px) in files/imagefiled_thumbs folder, but swfuplod widget searches those files in filefiled_path defined path.
My temporary solution: I was created symbolic link (ubuntu server) named imagefiled_thumbs in files and the target is in imagecache/[preset_100px_folder]
This solution may help.

ManyNancy’s picture

Can somebody create a patch so that this can be committed.

David Lesieur’s picture

Status: Active » Needs work
FileSize
1.08 KB

This patch corresponds to the above solution #3. It seems to work, but as mentioned in #7, the imagefield_thumbs do not get saved to the location defined by FileField Paths.

Danny_Joris’s picture

Subscribing. I have the same issue.

skourak’s picture

I'd also be very interested to see how this issue evolves. Meanwhile, thanks for the effort #3 and #9!

FranCarstens’s picture

This solution works, however there still doesn't seem to be a solution with tokens. I'm trying to add a path based on [user-raw] and it defaults to tmp. No file(s) uploaded. Without the use of tokens this works fine.

David Lesieur’s picture

Title: Problems with file object (Support for FileField Paths) » Add support for FileField Paths
EugenMayer’s picture

Status: Needs work » Fixed

pelase reopen this issue if the problem does still exist in beta5, i could not reproduce it there

David Lesieur’s picture

Version: 6.x-2.0-beta2 » 6.x-2.0-beta6
Status: Fixed » Active

I haven't looked at the code, but have tested beta6. It seems to have no improvement in supporting FileField Paths. Even simple file path settings with no tokens have no effect. File name cleanup settings are ignored. Uploaded files all end up in the 'files' directory.

ManyNancy’s picture

Same, not working.

Can the patch be updated?

milos.kroulik’s picture

+1

skilip’s picture

Can someone provide a patch for this issue?

David Lesieur’s picture

timbraeckman’s picture

Is the problem already fixed in a new release?

EugenMayer’s picture

No, not yet

ManyNancy’s picture

#9 was a good temporary solution. I hope someone who understands what was happening can update the patch, it doesn't work at all in the latest.

DMacpherson’s picture

I applied the patch in #3 to the swfupload_widget.inc file and, for the most part, it works. I was able to save a node with images and the images would get saved to a token [nid] directory. e.g. for images in node 12, it would save to the files/12 directory.

HOWEVER...

If I edit and resave the node (even without changing anything), I get this error:

warning: preg_match() expects parameter 2 to be string, array given in /srv/www/htdocs/drupal.6.14/includes/bootstrap.inc on line 777.

I'd get this error x2 per each node. e.g. if I have three nodes, this error appears six times. And it doesn't go away no matter how many times I refresh the node.

BUT...

If I edit the node and double-click the description fields (regardless of whether I actually edit the description or not) and then save, the preg_match errors go away.

David Lesieur’s picture

Status: Active » Needs work
FileSize
1.64 KB

Here's an updated patch that improves on #9 by creating the thumbnails at their expected location.

However it still needs work because old thumbnails (those created right after uploading, before saving the node) do not get cleaned up.

David Lesieur’s picture

Status: Needs work » Needs review
FileSize
4.11 KB

More improvements, thumbnail cleanup fixed.

EugenMayer’s picture

Thank you David!

timbraeckman’s picture

David thanks for the great patch. However... here it still doesn't use the filefield path :-(

David Lesieur’s picture

@DeLaPena: I'm really surprised to hear that. I'm successfully using the patch daily on a development site. Are you sure that the patch got properly applied? Could you detail the configuration of your field?

timbraeckman’s picture

David Lesieur... very weird... the patch didn't work for me so i tried re-installing all modules that have something to do with it and now it works... and even without your patch!! Is this possible?

David Lesieur’s picture

@DeLaPena: I don't see how SWFUpload could support FileField Paths without the patch.

ajagadees’s picture

Great, Thanks works for me :)

EugenMayer’s picture

Status: Needs review » Reviewed & tested by the community

Changing status. Thanks for the contribution and testers!

David Lesieur’s picture

Version: 6.x-2.0-beta6 » 6.x-2.0-beta7
FileSize
4.34 KB

Re-rolled to apply cleanly to beta7. No code change.

3dloco’s picture

+1

kmajzlik’s picture

please make beta8 with this change.

skilip’s picture

Committed. Thanks a bunch all!

ddorian’s picture

Status: Reviewed & tested by the community » Fixed

and fixed thanks

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.