Copy images between different sites/hosts using PHP

I am planing to build a CMS-system.

The CMS system will be located and fully administrated at: www.mycompany.com/customer

The final website will be located at: www.customer.com

I need to figure out the best way to copy files (eg. images) from: www.mycompany.com/customer/media to: www.customer.com/media

Note: The CMS and customer page will be located on different hosts. And I want to build this function using PHP.

Some thoughts:

The optimal solution would be if the two directories could be cloned automaticly, no matter how the images are uploaded or updated. Maby if there is a way to detect changes to www.mycompany.com/customer/media, then www.customer.com/media could be notifyed about it and send a request to update the image.

A wish would also be that images only could be accessed from www.mycompany.com/customer/media if logged in to the CMS :S

Any tips?

Answers


You should not use FTP (insecure), or PHP for the replication, try rsync instead :-

What is rsync ? http://en.wikipedia.org/wiki/Rsync

rsync is a software application and network protocol for Unix-like and Windows systems which synchronizes files and directories from one location to another while minimizing data transfer using delta encoding when appropriate. An important feature of rsync not found in most similar programs/protocols is that the mirroring takes place with only one transmission in each direction. rsync can copy or display directory contents and copy files, optionally using compression and recursion.

In another word, is designed meant for mirroring or replicating (is industry standard)

In general,

  1. setup public key to allow source server to able to ssh into destination server
  2. setup a cronjob in the source server to do rsync

What does the cronjob do ? In nutshell, it should rsync the selected source directory to destination server, a quick example :-

* * * * * rsync -avz /home/www.mycompany.com/www $HOST:/home/www.customer.com/www
                     ^ source server directory   ^ destination server, 
                                                   and directory

However, rsync is too hard to describe in few sentences, you can take a look :- http://www.cyberciti.biz/tips/linux-use-rsync-transfer-mirror-files-directories.html (as a start)

Other possibilities is make use of version controlling software, like -:

  1. git
  2. svn

Or make use on CDN (like @Amir Raminfar has mentioned), which itself is already a complete solution for file distribution.


Need Your Help

Kohana The requested URL /home was not found on this server

php apache .htaccess kohana kohana-3.3

I am getting this error from a red hat apache environment which is running php with a Kohana application. This application was migrated from a wamp installation where it was functioning.

Accessing global function inside js in html page on IE9

javascript html internet-explorer

I'm trying to access a global function that I declare inside my main.js file and try to use it in the html page:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.