|
Posted by Sandman on 02/26/07 15:10
Ok, so I'm the author of a pretty big CMS system (big as in huge, not
market-share big) and I've been thinking about a problem for a few
weeks here on media management.
The CMS accomodates both images/media uploaded by admins, but also by
members (in forum and blogs and such). Nothing strange about that at
all.
But now I'm faced with the need of moving - physically - all my media
to a separate server, for distributed loads. I.e. when deploying the
CMS you can either set localhost or media.exampel.com as your media
repository.
This makes for two problems - as far as I can think of:
1. Upload
Upon surfing to www.example.com, and uploading an image - the image
has to be moved to media.example.com after it has been uploaded to the
first server. Right? The media has to be moved first from the client,
to the www server and then from the www server to the media server. As
far as I can tell, there is no other way to do this. I have several
functions to handle uploaded files, the most important one is:
move_file($original_path, $to_dir);
And to handle this, this function has to know when media server isn't
"localhost" and facilitate the transfer to the other server, maybe by
a second POST to media.example.com?
2. <img> tags
The next problem is when the PHP script should output an image that is
physically located on another machine. Today, I use imagemagick to
convert it to the wanted size and geometry and saves it in a cache
directory and then outputs a <img> tag that points to this directory.
With the file on another server, the PHP script on the www server can
only output something along the lines of:
<img src='http://media.example.com/img.php?path=/path/to/file.jpg'>
For example. And img.php on media.example.com will do all the
conversions needed (in accordance to whatever size or geometry
specifications sent along in the IMG tag).
But, this isn't valid HTML. the <img> tag should always contain
width/height parameters or it will not validate. Not that my code
validates perfectly anyway, but I rather have this information since
it speeds up parsing by the browser as well.
Is there anyone out there that has done something like this before and
knows a good way to get something that isn't half-bad?
--
Sandman[.net]
Navigation:
[Reply to this message]
|