WordPress.org

Ready to get started?Download WordPress

Forums

Intercepting file after media upload? (6 posts)

  1. layered
    Member
    Posted 1 year ago #

    Hi,

    I've used Settings -> Media to define an alternate domain to serve static files (CSS, JS, IMG, for example) and it's working great as a dedicated CDN, but I've run into an issue and have a question about resolving it in the best way.

    What I'd like to do is intercept mp3 files (only) and upload them to an alternate domain; ie, a 2nd CDN. This may seem excessive, but I don't want any large audio files hogging up the stream as the rest of my site is slurped into the browser.

    I'm not very familiar with how WordPress works in terms of debugging. For example, sometimes a print_r will work, sometimes it won't, so I'm guessing that it depends where it's called. What I need to do is dump some variables from within the upload function to the screen so I can see what I have to work with. I'm looking at the wp_upload_bits function and it looks like the right place to find the data I need, but I just can't seem to get it printed out.

    I did try a whole slew of debug plugins, none of which worked -- presumably because they've not been updated for WP 3.4. But I also notice that Google is full of fresh posts about 3.4's debugging not working properly, so I wasn't sure if that might be related. A search here on the forums didn't turn up anything relevant, so after a year on WordPress, I finally had to break down and create an account here to ask for some help. (That speaks volumes to the docs and the myriad of support sites out there!)

    Any insights would be greatly appreciated!

    Thanks!

  2. s_ha_dum
    Member
    Posted 1 year ago #

    ...sometimes a print_r will work, sometimes it won't...

    Try putting die(); right after the print_r.

  3. layered
    Member
    Posted 1 year ago #

    Thanks for the reply. I did try that, as well as following it with wp_die and then even tried a basic exit. None of these methods worked. The script just went on its happy way and rendered the page settings for the file that was just uploaded; it seemingly ignored my intention to kill the script in place and the variables weren't printed to the screen.

  4. bcworkz
    Member
    Posted 1 year ago #

    If the script doesn't die, it can only mean code execution never reached the die statement. It's not possible to reach a die statement and have the code continue to execute.

  5. layered
    Member
    Posted 1 year ago #

    bcworkz, yes, that was my thought as well. I was testing with a small jpg and it did indeed upload to the CDN domain, so I thought I could interrupt it in the middle of that function. That would mean that function isn't actually the one saving the file to the server, even though it thoroughly appears to be (to me!) so that leads me to wonder:

    If it's not wp_upload_bits() that saves files to the server when we upload through the built-in media uploader and have an alternate path/url set (via settings, not wp-config.php), which function actually does do this?

  6. s_ha_dum
    Member
    Posted 1 year ago #

    If it's not wp_upload_bits() that saves files to the server when we upload through the built-in media uploader and have an alternate path/url set (via settings, not wp-config.php), which function actually does do this?

    I have not looked into 3.4 but it used to be media_handle_upload

Topic Closed

This topic has been closed to new replies.

About this Topic