Skip to main content
Home
The Baheyeldin Dynasty
The journey for wisdom starts with knowledge
  • Home
  • About
  • Site Map
  • Contact

Tips On Migrating Drupal image module From 4.5 to 4.6

  1. Home

By Khalid on 2005/11/30 - 21:02, last updated 2005/11/30 - 21:19

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. 

Contents: 
Drupal
  • Add comment

Current

Pandemic

  • COVID-19
  • Coronavirus

Search

Site map

Contents

  • Family
    • Khalid
    • Ancestry
    • Extended
  • Friends
  • Nokat نكت
  • Writings
    • Cooking
    • Culture
    • Science
    • History
    • Linguistics
    • Media
    • Literature
    • Politics
    • Humor
    • Terrorism
    • Business
    • Philosophy
    • Religion
    • Children
  • Technology
    • Linux
    • Arabization
    • Drupal
      • Association
    • Software
    • Internet
    • Technology in Society
    • Digital Archeology
    • NCR History
    • MidEast Internet
    • Programming
    • Saudi ISPs
    • Miscellaneous
  • Places
    • Canada
      • Weather
    • Egypt
      • Cuisine
      • Alexandria
      • E.G.C.
    • USA
    • Saudi Arabia
  • Interests
    • Astronomy
    • Fishing
    • Photography
    • Snorkeling
    • Nature
    • Photomicroscopy
  • Miscellany

In Depth

  • al-Hakim bi Amr Allah: Fatimid Caliph of Egypt الحاكم بأمر الله
  • Alexandria, Egypt
  • Arabic on the Internet
  • Articles on the history of Muslims and Arabs in the Iberian Peninsula تاريخ المسلمين و العرب في الأند
  • DIY GOTO Telescope Controller With Autoguiding and Periodic Error Correction
  • E.G.C. English Girls College in Alexandria, Egypt
  • Egyptian Cuisine, Food and Recipes مأكولات مصرية
  • George Saliba: Seeking the Origins of Modern Science?
  • Internet Scams and Fraud
  • Mistaken for an Arab or Muslim: Absurdities of being a victim in the War on Terror
  • Mistaken Identity: How some people confuse my site for others
  • One People's Terrorist Is Another People's Freedom Fighter
  • Overview of Google's Technologies
  • Photomicroscopy
  • Pseudoscience: Lots of it around ...
  • Resources for using Google Adsense with Drupal
  • Rockwood Conservation Area, Southern Ontario
  • Selected Symbolic Novels And Movies
  • Snorkeling the Red Sea near Jeddah
  • Updates and Thoughts on the Egyptian Revolution of 2011

Recent Content

Most recent articles on the site.

  • Origin Of COVID-19: Natural Spillover, Lab Leak Or Biological Weapon?
  • Kamal Salibi and the "Israel from Yemen" theory
  • How To Upgrade HomeAssistant Core In A Python Venv Using uv
  • Ancestry - Paternal Side
  • Review of Wait Water Saver For Whole House Humidifiers
more

Most Comments

Most commented on articles ...

  • Another scam via Craigslist: offering more than asking price
  • Warning to female tourists thinking of marrying Egyptians
  • Craigslist classified for used car: Cheque fraud scam
  • Winning the lottery scam email: World Cup South African lottery
  • Email Scam: BMW 5 Series car and lottery winning
more

About Khalid

Various little bits of information ...

  • Khalid Baheyeldin: brief biography
  • Presentations and Talks
  • Youtube Videos
  • GitHub Projects
  • Drupal.org Profile
  • Astrophotography @ Flickr

Sponsored Links

Your Link Ad Here

Tags

Android Mobile Ubuntu Sony OnStep OpenWRT Router Ericsson COVID-19 Rogers Coronavirus Arabic Kubuntu Home Assistant GSM Telescope tablet Spectrum Scam Python 419 Laptop Firefox DIY CPU Conspiracy Comet Balkanization backup App
More

© Copyright 1999-2025 The Baheyeldin Dynasty. All rights reserved.
You can use our content under the Terms of Use.
Please read our privacy policy before you post any information on this site.
All posted articles and comments are copyright by their owner, and reflect their own views and opinions, which may not necessarily be consistent with the views and opinions of the owners of The Baheyeldin Dynasty.

Web site developed by 2bits.com Inc.