Support » Plugins » Plugin relocate-upload – Not quite working in 2.7

  • I’m afraid this plugin is not working (at least for me) in WP 2.7 because when a file is first uploaded to the default folder the corresponding row in db table wp_postmeta holds just the filename, not path and filname. So
    $attachment_path=get_post_meta($id,"_wp_attached_file",true);
    does not get the right value. That is why
    if (rename($attachment_path,$new_path))
    does not work and returns false.

    Maybe you should check if the filename is stored with or without path in wp_postmeta and construct $attachment_path accordingly.

    http://wordpress.org/extend/plugins/relocate-upload/

Viewing 15 replies - 16 through 30 (of 61 total)
  • I have now and it works! Thanks again – essential plugin I think.

    Regards
    Lynne

    I’ve tried both the development version and the regular and have not been able to get it to work.

    I am able to add a directory but when I try to move a file it says “moving..” then it says “failed”. I did make sure this directory exists and that it has permissions 777.

    Any idea where I’m going wrong?

    no idea from what you say. tell me what it says on your Relocate Upload Settings page, specifically the values of the text fields you have set and the ‘Default Location’, and also the “Paths are relative to the blog root: xxx” text, and finally where you are trying to switch locations between. what sort of server are you on too could help.

    Thanks so much for all your help! I love this plugin. I had the same problem as barney_1 until I changed line 38. But right now I’m encountering another problem. Once I select a folder to relocate my file to, the thumbnail URL changes and therefore the thumbnail image becomes broken.

    This is how the thumbnail URL’s supposed to look:
    http://site.com/scans/thumbnail.jpg

    But instead it looks like this:
    http://site.com/wp-content/uploads//home/site/public_html/scans/thumbnail.jpg

    What’s up?

    Good point about the line 38 fix – barney, check up thread for that – it might be what you need.

    paintpops – yes there is an issue there which i need to resolve. I *think* that its a shortcoming in the WP core code that assumes your media items will always be inside wp-content/uploads. i’ve been thinking about raising a ticket or whatever it is that you have to do on these projects. (i might dig out my findings on this and post here in a bit.)

    i have recently patched it on my own install with a filter – which is a bit poor – and i’ll be putting it in the main code when i work out how to make it work generically. For now you can patch it with something like:

    add_filter( 'wp_get_attachment_url', "wp_get_attachment_url_base_folder");
    
    function wp_get_attachment_url_base_folder($url)
    {	$url=str_replace("/wp-content/uploads//home/site/public_html/","/",$url);
    	return $url;
    }

    put it in your theme’s functions.php or add it to the plugin code

    follow up, it’s a failure of both WP and my plugin of course

    the wp_get_attachment_url function (a central function called eg by wp_get_attachment_thumb_url) in wp-includes/post.php does assume everything is in the upload folder or it falls back on the old-fashion “guid” of the attachment

    so it looks like the guid rewiring in the plugin is not getting it right.

    it’s confusing cos the _wp_attached_file postmeta USED to be absolute, but at some point (2.6/2.7) they switched to being relative the uploads folder.

    I didn’t get that quite right. it USED to fallback to the guid, but the code in wp_get_attachment_url currently does this

    if ( 0 === strpos($file, $uploads['basedir']) ) //Check that the upload base exists in the file location
    	$url = str_replace($uploads['basedir'], $uploads['baseurl'], $file); //replace file location with url location
    elseif ( false !== strpos($file, 'wp-content/uploads') )
    	$url = $uploads['baseurl'] . substr( $file, strpos($file, 'wp-content/uploads') + 18 );
    else
    	$url = $uploads['baseurl'] . "/$file"; //Its a newly uploaded file, therefor $file is relative to the basedir.

    which translates as

    if the /path/to/wordpress/wp-content/uploads path is in the file path, then it replace that path with http://yrdomain.com/wordpress/wp-content/uploads

    OTHERWISE

    if you can find “content/uploads” anywhere in the filepath replace text up to that with http://yrdomain.com/wordpress/wp-content/uploads

    OTHERWISE

    just put http://yrdomain.com/wordpress/wp-content/uploads/ on the start of the filepath (probably as this is the old relative to uploads filepath WP *used* to do)

    which means it will not fall back on the guid (which the plugin does rewire correctly!). I’d rather it didn’t use that final otherwise and instead did fail back to the guid, as it means, you can no longer have media items outside of the uploads path! my plugin is violating that assumption, so I’m not going to raise a ticket to get that assumption changed. instead i’ll work out the proper wp_get_attachment_url filter function to use (as shown for the specific case above)

    excuse my long-windedness, they sort of work as notes to self and to update the dev version.

    HERE’S YOUR SHORT ANSWER…

    add this code on the end of relocate-upload.php

    add_filter( 'wp_get_attachment_url', "wp_get_attachment_url_base_folder");
    
    function wp_get_attachment_url_base_folder($url)
    {	$url=preg_replace('#(http://.*?/).*?/'.($GLOBALS['_SERVER']['DOCUMENT_ROOT']).'/#','\1',$url);
    	return $url;
    }

    i think this will work as a generic fix for the problem

    a-and finally, i have updated the dev version with all the above fixes

    will tag it as an updated release soon, as it looks good here.

    thanks a bunch! =) it’s working fine now and the thumbnails show up properly

    i know this may be asking for too much, but i just want to make a suggestion for batch relocation, if possible =) that would really save a lot of time from having to manually move each file.
    looking forward to the development version though!

    oo, batch relocation might be fun to work out how to do. the items in the media library list have that tick box and there’s the bulk actions drop down. i could see if i can add an action to that – or a second drop down next to it.

    may have time to fiddle with that 🙂

    that would be awesome =) i’m currently using the “faster image insert” plugin as well and they have a mass edit function, so maybe something of that sort?

    http://blog.ticktag.org/2009/02/19/2765/

    Hi! I wanted to use your plugin, but it won’t work.

    Whenever I want to relocate a picture to another folder, it says: “Failed”.

    But the settings are right, there is no error. I’m Using WP 2.7
    The folders do exist. So why is this error?

    I’m sorry. I downloaded the latest dev version, and there it works fine!

Viewing 15 replies - 16 through 30 (of 61 total)
  • The topic ‘Plugin relocate-upload – Not quite working in 2.7’ is closed to new replies.