Recently a client wanted to move their site from 4.5 to 4.6.3. They happen to use the image module. Although they initially said that the images are just "icing on the cake", and that they could repost them, I discovered that they had 500+ images already in many galleries.
I decided to spend some time and try to migrate the images over.
With the 4.6 version, the image module has an update-image.php script that should migrate your old data from the image table to the standard files table of Drupal. Problem is: it did not work. After some debugging, it seemed that it was confused on file locations.
I wanted to move the images from the files/images directory to the sites/default/files/images directory, so as to isolate Drupal's core files from site specific ones. This makes for easier upgrades in the future, and also simplifies backups.
So, the first step was to change the File System Location in Administer -> Settings.
Workaround
In the image.module file, you will find a function that is called by update-image.php called _image_insert(). This function looks like this:
function _image_insert($nid, $label, $image) {
$dest = _image_filename(basename($image));
if (file_copy($image, $dest)) {
$info = image_get_info(file_create_path($dest));
$file->filename = $label;
$file->filepath = _image_filename(basename($image));
$file->filemime = $info['mime_type'];
I changed the function to be like this (note there are only two lines change). Change the 'sites/default/files/images' line to the directory you want images to go to, if it is different, for example, 'sites/www.example.com/files/images'.
function _image_insert($nid, $label, $image) {
//$dest = _image_filename(basename($image)); <=== THIS LINE
$dest = 'sites/default/files/images/' . basename($image);
if (file_copy($image, $dest)) {
$info = image_get_info(file_create_path($dest));
$file->filename = $label;
//$file->filepath = _image_filename(basename($image)); <=== THIS LINE
$file->filepath = $dest;
$file->filemime = $info['mime_type'];
I then ran the update-image.php script just like the instructions said, and the migration was successful.
It is important that you now undo the change you made, so that image module will work properly. You may also want to cleanup the files directory since it is no longer needed.
Most Comments
Most commented on articles ...