Title: [Feature] Handle Missing Files (Code supplied)
Last modified: March 28, 2017

---

# [Feature] Handle Missing Files (Code supplied)

 *  [denyerec](https://wordpress.org/support/users/denyerc/)
 * (@denyerc)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/feature-handle-missing-files-code-supplied/)
 * I discovered when trying to pull a site down to my local dev machine that this
   plugin doesn’t handle missing media files and silently fails.
 * This is because it tries to do a get_attached_file call to recover the path information
   for the file you want to replace.
 * Around line 70 of upload.php for the plugin, put this:
 *     ```
       $ulPath = wp_get_upload_dir();
       if(strpos($current_file, $ulPath['basedir']) === FALSE){
               $current_file = $ulPath['basedir'] . str_replace($ulPath['baseurl'],'',$current_guid);
       }
       unset($ulPath);
       ```
   
 * And it’ll catch missing files and allow you to replace them just fine. Would 
   be nice to have this checked over and added to the next release.
    -  This topic was modified 9 years, 2 months ago by [denyerec](https://wordpress.org/support/users/denyerc/).

The topic ‘[Feature] Handle Missing Files (Code supplied)’ is closed to new replies.

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

 * 0 replies
 * 1 participant
 * Last reply from: [denyerec](https://wordpress.org/support/users/denyerc/)
 * Last activity: [9 years, 2 months ago](https://wordpress.org/support/topic/feature-handle-missing-files-code-supplied/)
 * Status: not resolved