Title: Error with search_db_files() function
Last modified: July 16, 2021

---

# Error with search_db_files() function

 *  [leanderbraunschweig](https://wordpress.org/support/users/leanderbraunschweig/)
 * (@leanderbraunschweig)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/error-with-search_db_files-function/)
 * Hi there,
 * I noticed a flaw in the `search_db_files()`-function (in `class-bulkmediaregister.
   php`):
 * You are using PHP’s `rtrim()` in order to strip the **‘-scaled’**-part of the
   file but this isn’t a safe operation and leads to missed files when checking 
   for already registered ones in the DB.
 * One of our files that was missed is:
 * _/srv/www/hackeundspitze.de/releases/20210715063114/web/app/uploads/rclone/HiddenBeautyOfSeedsFruit\
   _p020a-scaled.jpg_
 * Once `rtrim()` is done processing we get:
 * _/srv/www/hackeundspitze.de/releases/20210715063114/web/app/uploads/rclone/HiddenBeautyOfSeedsFruit\
   _p020.jpg_
 * Yields the same result if you append other characters that are part of the trimming-
   sequence, f.ex. _HiddenBeautyOfSeedsFruit\_p020asclddaa-scaled.jpg_ will also
   be stripped completely into _HiddenBeautyOfSeedsFruit\_p020.jpg_.
 * You should use a RegEx-based approach which is way more fail-proof:
 *     ```
       $scaled = '/-scaled\.' . $filetype['ext'] . '/m';
       $file2 = preg_replace( $scaled, '', $file1 ) . '.' . $filetype['ext'];
       ```
   
 * Should be refactored for **‘-rotated’** as well obviously.
 * Regards,
    Henning
    -  This topic was modified 4 years, 10 months ago by [leanderbraunschweig](https://wordpress.org/support/users/leanderbraunschweig/).

The topic ‘Error with search_db_files() function’ is closed to new replies.

 * ![](https://ps.w.org/bulk-media-register/assets/icon-256x256.png?rev=2316228)
 * [Bulk Media Register](https://wordpress.org/plugins/bulk-media-register/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/bulk-media-register/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/bulk-media-register/)
 * [Active Topics](https://wordpress.org/support/plugin/bulk-media-register/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/bulk-media-register/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/bulk-media-register/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [leanderbraunschweig](https://wordpress.org/support/users/leanderbraunschweig/)
 * Last activity: [4 years, 10 months ago](https://wordpress.org/support/topic/error-with-search_db_files-function/)
 * Status: not resolved