Posted by PGiro on May 31, 2009 at 9:41pm
| Project: | Mailsave |
| Version: | 6.x-1.3 |
| Component: | Code |
| Category: | task |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (duplicate) |
Issue Summary
I have a node type that holds an imagefield. I have setup its path to be [user-id]/[site-date-YYYY]/[site-date-MM]/[site-date-DD].
When I use mailsave_to_imagefield, the files are not saved to this directory because it is not created on the fly when it does not exist. I have traced the code to that problem and I'm not sure there is a good solution (there must be... this is drupal).
It's all happening in _mailsave_to_imagefield_attempt_image() whene iterating the attachements
// Let's create the directory path if it hasn't been created already
$directory = file_create_path($widget_image_path);
file_check_directory($directory, FILE_CREATE_DIRECTORY);That first line does not create the directory is it doesn't exist when it really should. That's because PHP's realpath() returns an empty string when a path does not exist (at least in 5.x)
Comments
#1
Here is my unsatisfactory fix but I can't think of anything better at the moment
$directory = file_directory_path()."/".$widget_image_path; //was file_create_path($widget_image_path);module_load_include('inc','filefield','field_file'); // added
field_file_check_directory($directory, FILE_CREATE_DIRECTORY); // was file_check_directory($directory, FILE_CREATE_DIRECTORY)
#2
Thanks, I incorporated this patch in #315381: make mailsave_to_imagefield work with mailhandler for importing images to cck imagefields.
#3
How i "succeded"
My Fix was replacing Line 107 in mailsave_to_imagefield.module
// Let's create the directory path if it hasn't been created already
$directory = file_create_path($widget_image_path);
file_check_directory($directory, FILE_CREATE_DIRECTORY);
$destination = file_destination(file_create_path($widget_image_path .'/'. $file['filename']), FILE_EXISTS_RENAME);
file_move($file['filepath'], $destination);
with
// Let's create the directory path if it hasn't been created already
$directory = file_directory_path()."/".$widget_image_path; //was file_create_path($widget_image_path);
module_load_include('inc','filefield','field_file'); // added
field_file_check_directory($directory, FILE_CREATE_DIRECTORY); // was file_check_directory($directory, FILE_CREATE_DIRECTORY)
$destination = file_destination(file_create_path($widget_image_path .''. $file['filename']), FILE_EXISTS_RENAME);
file_move($file['filepath'], $destination);
Note: I had to remove the trailing slash /
$destination = file_destination(file_create_path($widget_image_path .' / '. $file['filename']), FILE_EXISTS_RENAME);
With a little help...
I also downgraded to mailhandler 6.x-1.8 and downloaded an complete package of mailsave with fixed mailsave_to_imagefield from this post:
http://drupal.org/node/714402
Steps
Attached is my complete Version of Mailsave-Fixed-Refix and Mailhandler.
#4
Confirming that the solution in comment number 3 works. I tried it (make sure you use mailhandler 1.8, not the latest version):
Thanks to kloewer. Note that there are four other issues pertaining to this:
This issue we are on now is already marked as a duplicate, and I've marked the three others as duplicates, of #315381: make mailsave_to_imagefield work with mailhandler for importing images to cck imagefields. so let me suggest we continue the discussion there.
#5
Same issue with mailsave_to_video
Solution: http://drupal.org/node/774294#comment-3063090
#6
I just wanted to say that yes, comment #3 did work for me. ALSO, it's working using the latest version of mailhandler, which is 1.11. However, I did NOT need to make the change that kloewer made to generate $destination... the '/' does not need to be removed... I'm guessing he needed to remove it because there was a trailing slash on his $widget_image_path, but the imagefield module specifically says that there should not be. So, the only code that should need to be changed from what's described in http://drupal.org/node/714402 is around line 107:
$directory = file_directory_path()."/".$widget_image_path; //was file_create_path($widget_image_path);module_load_include('inc','filefield','field_file'); // added
field_file_check_directory($directory, FILE_CREATE_DIRECTORY); // was file_check_directory($directory, FILE_CREATE_DIRECTORY)
So, now we've got a fix for this module with the latest version of mailhandler... how about an update? :)