Support » Plugins » changing upload url, now not uploading

  • Resolved laurim


    I upgraded to 2.02 hoping to be able to upload files to the directory of my choice but was disappointed to find it still forced me to create a directory under the WP directory. I want new images and media files to be placed in a _media directory at my root. I also want the upload function to work this way in the Post Edit page to make it simple for my client so I don’t want to use that upload plugin that gets back to an old version Uploads page.

    I discovered that I can simply edit the wp-includes/functions-post.php file and change the line that retrieves the site url (where WP is installed) to retrieve the home url instead (my root).

    function wp_upload_dir() {
    $siteurl = get_settings('home');
    instead of
    $siteurl = get_settings('siteurl');

    When I test it by editing a post, WP goes through the motions to upload the file to my desired location (correct based on the link I get when I add it to a post) WITHOUT ERROR but the file is never actually uploaded.

    Is there another bit of code I need to edit to get WP to actually upload the file to the correct location, outside the WP directory?

    PS I thought it might be a permissions thing so I made the permissions on my root 777. Still nothing.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Try adding the following to your wp-config.php file (before it includes wp-settings.php):

    define('UPLOADS', '/images');

    Modify “images” if using a different directory name. If that doesn’t quite work, try providing a path traversal to the image directory path to negotiate up from the WP directory (assuming your WP install is in a subdirectory to the root):

    define('UPLOADS', '../images');

    It might help to set functions-post.php back to the original, as well.

    I tried that I’m afraid. Images still go into the WP directory in whatever subfolder I specified.

    If I don’t change functions-post to use the “home” reference instead of the “siteurl” reference, anything I put in the config file gets tacked onto the end of ( for your example) and gets uploaded within the wp directory.

    I can’t find a method that will get me to that ACTUALLY uploads the file to that folder. WP creates the correct url that gets used when I add the image to a post but doesn’t actually upload the file and I don’t get an error to tell me what the problem is.

    None of my site’s content files are in the WP directory because I’m using it as a CMS, not using the templates. I’d like ALL the site files to reside outside the WP directory just as a matter of consistency and to make it easy to upgrade without accidentally deleting my uploaded files.

    I’ve found if I hardcode the desired directory path into functions-post it works. Naturally, this isn’t an ideal method since I’d like to just change the config file for each client rather than hack the include file.

    Found it! I didn’t realize ABSPATH was the path to WP. When I replaced that with $_SERVER[‘DOCUMENT_ROOT’] it works and I don’t even have to set anything in the config file:

    function wp_upload_dir() {
    $siteurl = get_settings('home');
    $path = get_settings('upload_path');
    $dir = trailingslashit($_SERVER['DOCUMENT_ROOT']) . $path;
    $url = trailingslashit($siteurl) . $path;

    Awesome, exactly what I was looking for after 2 hours searching. Don’t forget to remove any path info from the default upload setting.

    I came back to read this page and realize to the newcomer it’s pretty confusing.

    The steps to upload files and images outside of WP.

    Add to wp-includes/functions-post.php:
    function wp_upload_dir() {

    // home was siteurl
    $siteurl = get_settings(‘home’);

    // Upload path is set in Options:Miscellaneous. Put the path to images there, starting with the document root of your server. For me it’s /images
    $path = get_settings(‘upload_path’);

    // Document_root is just what it sounds like. ABSPATH is the path to WP, which is why whatever you put in the file upload setting will be appended to the location of wp and make it a subdirectory

    $dir = trailingslashit($_SERVER[‘DOCUMENT_ROOT’]) . $path;
    $url = trailingslashit($siteurl) . $path;

    Don’t change anything in wp-config.php.

    FYI My solution above no longer works with 2.1.2. Trying to get someone to come up with a revision to my changes to get it to work, should be simple.

    Any luck with 2.1.2?

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘changing upload url, now not uploading’ is closed to new replies.