Author Topic: [Ready] autosaving uploaded image with name - $IMAGE_ID  (Read 7375 times)

0 Members and 1 Guest are viewing this topic.

Offline Dandily

  • Pre-Newbie
  • Posts: 5
    • View Profile
[Ready] autosaving uploaded image with name - $IMAGE_ID
« on: June 28, 2005, 07:03:13 PM »
Hello everybody!

When i upload image in 4im, it saves on site with original file name. How can i do that images names will be IMAGE_ID.jpg?
I`m not very good in 4im structure, so it`ll take a lot of time to me to find where to make changes. I think thats not a big problem for old users of 4im. So i ask if anybody can help me in that :)

Thanks a lot.
« Last Edit: January 19, 2009, 03:40:44 AM by Dandily »

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [REQ] autosaving uploaded image with name - $IMAGE_ID
« Reply #1 on: July 01, 2005, 12:06:57 AM »
this question was asked before, and no real solution was provided.
The reason is that image file being saved before the new image being added into the database, so the image id is not avalable when image being renamed (if needed) and saved to the correct path.

Other words, u'll need to rename the media file and thumbnail and then update the database with new filename.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [REQ] autosaving uploaded image with name - $IMAGE_ID
« Reply #2 on: July 01, 2005, 12:40:15 AM »
ok, here is a beginning, it works only for "direct upload" images (without validation)

in member.php find:
Code: [Select]
      if ($config['upload_notify'] == 1 && !$direct_upload) {Insert above:
Code: [Select]
      if ($direct_upload) {
        function _rename($old, $new){
          $cwd = getcwd();
          chdir(realpath(dirname($old)));
          $ok = (rename(basename($old), basename($new))) ? 1 : 0;
          chdir($cwd);
          return $ok;
        }
        $media_path = MEDIA_PATH."/".$cat_id."/";
        $thumb_path = THUMB_PATH."/".$cat_id."/";
        $media_ext = strtolower(substr(strrchr($new_name,"."), 1));
        $thumb_ext = strtolower(substr(strrchr($new_thumb_name,"."), 1));
        $new_media = (_rename($media_path.$new_name, $media_path.$image_id.".".$media_ext)) ? $image_id.".".$media_ext : $new_name;
        $new_thumb = (!empty($new_thumb_name) && _rename($thumb_path.$new_thumb_name, $thumb_path.$image_id.".".$thumb_ext)) ? $image_id.".".$thumb_ext : $new_thumb_name;
        $sql = "UPDATE ".IMAGES_TABLE."
                SET image_media_file = '$new_media', image_thumb_file = '$new_thumb'
                WHERE image_id = $image_id";
        $site_db->query($sql);
      }

Tested on v1.7.1
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Dandily

  • Pre-Newbie
  • Posts: 5
    • View Profile
Re: [REQ] autosaving uploaded image with name - $IMAGE_ID
« Reply #3 on: July 06, 2005, 03:57:16 PM »
Thanks a lot, it works fine!

Offline jotabonfim

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
Re: [REQ] autosaving uploaded image with name - $IMAGE_ID
« Reply #4 on: September 11, 2008, 04:16:07 PM »
Vano hello, in version 1.7.6 does not work.

tks

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [REQ] autosaving uploaded image with name - $IMAGE_ID
« Reply #5 on: September 12, 2008, 12:43:58 AM »
Doesn't work how?
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Dandily

  • Pre-Newbie
  • Posts: 5
    • View Profile
Re: [REQ] autosaving uploaded image with name - $IMAGE_ID
« Reply #6 on: January 19, 2009, 03:36:33 AM »
in 1.7.6 works fine!

Thanks again V@no)

Вся Россия тебе благодарна ;)