Closed (fixed)
Project:
Media API
Version:
5.x-5.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
10 Jan 2008 at 13:33 UTC
Updated:
25 Jan 2008 at 14:12 UTC
I use media_item_create with the filename as the only parameter, this sends a media object to media_item_insert with $media->path set to the file name.
media_item_insert however, tries to copy the complete path+the filename again ( /tmp/image.gifimage.gif). This is the failing section:
$name = (!empty($media->name) ? $media->name : media_file_name($media->path));
$ext = (!empty($media->ext) ? $media->ext : media_file_ext($media->path));
$fname = $name .'.'. $ext;
if (!($file = media_file_copy($media->path . $fname, $path . $fname))) {
media_error(t('Unable to copy !filename to !path', array('!filename' => $media->path . $fname, '!path' => $path . $fname)));
return FALSE;
}
As you can see, if $media->name is not set - the filename will become double.
Suggested replacement:
$name = (!empty($media->name) ? $media->name : media_file_name($media->path));
$ext = (!empty($media->ext) ? $media->ext : media_file_ext($media->path));
$target = $name .'.'. $ext;
if (empty($media->name)){
$source = "";
} else {
$source = $target;
}
if (!($file = media_file_copy($media->path . $source, $path . $target))) {
media_error(t('Unable to copy !filename to !path', array('!filename' => $media->path . $source, '!path' => $path . $target)));
return FALSE;
}
Comments
Comment #1
rhys commentedI changed a few things, including what happens in media_item_create, so that the process works fine.
Both having a media object with only the path set, as well as having everything set, has been accounted for.
Updated in the CVS.
Comment #2
Ibn al-Hazardous commentedCool, thanks! (Goes for the other bugfix as well. :)
Comment #3
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.