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:

The final website will be located at:

I need to figure out the best way to copy files (eg. images) from: to:

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, then 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 if logged in to the CMS :S

Any tips?


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

What is 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/ $HOST:/home/
                     ^ source server directory   ^ destination server, 
                                                   and directory

However, rsync is too hard to describe in few sentences, you can take a look :- (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.