• room58

    (@room58)


    I’ve set my upload folder in Admin, and wish to include a file that I have uploaded. I know the location of the file, but wish to use a pointer to the upload folder, much as you can point to the stylesheet folder using bloginfo(”). Is there one for uploads? I can’t find it!

Viewing 4 replies - 1 through 4 (of 4 total)
  • cheesemasterdan

    (@cheesemasterdan)

    I always use:
    ABSPATH . "wp-content/uploads/"
    but if anyone knows of a WP command to get the path I would be very interested also…
    Or get_bloginfo('wpurl')."/wp-content/upolads/" if you don’t want the absolute path (for a hyperlink or whatever)…

    Kafkaesqui

    (@kafkaesqui)

    Use:

    $upload_dir = wp_upload_dir();

    $upload_dir is now an array containing:

    $upload_dir['path'] : Server directory path.
    $upload_dir['url'] : URL to upload directory.

    cheesemasterdan

    (@cheesemasterdan)

    Excellent info… Thanks muchly Kafkaesqui!!

    Kafkaesqui

    (@kafkaesqui)

    Forgot to note this is a *dynamic* value, in that if one is organizing uploads under month/year-based directories, it returns the *current* upload directory. So $upload_dir['url'] would return something like:

    https://my-site/wp-content/uploads/2006/02

    today, but will change next month. For those organizing your upload attachments this way, here’s how you can grab just the top level upload dir while still using wp_upload_dir():

    $upload_dir = wp_upload_dir();
    $upload_path_base = preg_replace('|/([0-9]{1,4})/([0-9]{1,2})|', '', $upload_dir['path']);
    $upload_url_base = preg_replace('|/([0-9]{1,4})/([0-9]{1,2})|', '', $upload_dir['url']);

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘What is the upload folder $string?’ is closed to new replies.