4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Requests & Discussions) => Topic started by: Dandily on June 28, 2005, 07:03:13 PM

Title: [Ready] autosaving uploaded image with name - $IMAGE_ID
Post by: Dandily 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.
Title: Re: [REQ] autosaving uploaded image with name - $IMAGE_ID
Post by: V@no 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.
Title: Re: [REQ] autosaving uploaded image with name - $IMAGE_ID
Post by: V@no 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
Title: Re: [REQ] autosaving uploaded image with name - $IMAGE_ID
Post by: Dandily on July 06, 2005, 03:57:16 PM
Thanks a lot, it works fine!
Title: Re: [REQ] autosaving uploaded image with name - $IMAGE_ID
Post by: jotabonfim on September 11, 2008, 04:16:07 PM
Vano hello, in version 1.7.6 does not work.

tks
Title: Re: [REQ] autosaving uploaded image with name - $IMAGE_ID
Post by: V@no on September 12, 2008, 12:43:58 AM
Doesn't work how?
Title: Re: [REQ] autosaving uploaded image with name - $IMAGE_ID
Post by: Dandily on January 19, 2009, 03:36:33 AM
in 1.7.6 works fine!

Thanks again V@no)

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