There are existing plugins: http://wordpress.org/extend/plugins/tags/s3
You may want to consider them before reinventing the wheel 🙂
Thread Starter
kenrik
(@kenrik)
I already checked out the plugins that are out there. I prefer not to rely on third parties to keep my site functional if WordPress gets updated and the plugin is not compatible I’m SOL. I’m tying the site into an iPhone App so I’m going to have traffic from every user of the App and I have no way to predict the traffic that will result so that’s a big reason for S3.
Is there any reason that just using .htaccess to rewrite the path for the uploads folder would not work?
I honestly don’t know, and because I know jack about S3 and how IT works, I thought, perhaps, it would be better to grab an existing plugin and rip it apart. See how IT works, and if there are comments about why they DON’T just use .htaccess 😀
Thread Starter
kenrik
(@kenrik)
Well, basically anything I put in S3 is available at media.groceryvine.com because I pointed a cname @ S3.
So If I have a file at “http://groceryvine.com/wp-content/uploads/file.jpg” and I upload the entire uploads folder to S3 then the same file will be at “http://media.groceryvine.com/wp-content/uploads/file.jpg”
In theory all I have to do is add “media.” the front of any url that’s in “/wp-content/uploads” and it will pull the file from S3s massive network rather then my single server.
Then all I would have to do is poll my uploads folder for changes and it will automatically upload anything new. There will be a slight delay before the image goes live but I think it’s worth it for the benefits.
I guess I’ll just try it out and see if it works as well in practice as it does in my head.
Thanks, I’ll report back after I try my experiment.
Thread Starter
kenrik
(@kenrik)
It works!
If anyone is interested in a plugin.. here it is, like 6 lines of code and all uploads are served from S3.
Just set a S3 bucket of media.yoursite.com and point a cname at amazonaws.com. put in your URL in the plugin, activate and you’re done.
then you just need to keep your uploads folder in wordpress in sync with your uploads folder on S3.
With something this simple even a cave man can do it..
<?php
/*
Plugin Name: Rewrite
Plugin URI: http://SudoWorks.com
Description: Rewrites your image paths so that you can use a CDN.
Version: 2.4
Author: SudoWorks
Author URI: http://SudoWorks.com/
*/
function rewrite_url($rewrite)
{
$rewrite = str_replace('yoursite.com/wp-content/uploads/', 'media.yoursite.com/wp-content/uploads/', $rewrite);
return $rewrite;
}
add_filter('wp_get_attachment_url', 'rewrite_url');
?>
This doesn’t look like a multisite issue at all and I think you have a single site, yes?
For multisite w3 total cache works perfect and it has a nice feature of exporting all your existing sites to CDN without any headache and deploy all the settings easily. I was able to do it with amazon s3 and rackspace cloudfiles.