Search code examples
phpmysqlserver-side

Upload directory for two different hosts


I have two different services, websites on two different hosts, and there's one shared thing - Upload directory. Do you have some idea, how to solve that problem ? Or just how to share one admin Panel between two different websites, on two different hosts ?


Solution

  • I recommend you set up an FTP server, then upload the files to that FTP.

    I normally use phpseclib library when working with FTPs (this library supports SFTP)

    You will have access to all the files on the FTP from any of the servers.

    Sample usage:

    $sftp = new Net_SFTP('www.domain.tld');
    $sftp->login('username', 'password');
    $sftp->chdir('upload');
    $sftp->put('filename.remote', 'xxx'); // string to be uploaded or file_get_contents('local.file')
    $sftp->put('filename.remote', 'local.file', NET_SFTP_LOCAL_FILE);
    $remoteFileContent = $sftp->get('filename.remote');
    $sftp->get('filename.remote', 'local.file'); // copy remote file
    $sftp->delete('filename.remote'); // delete file
    

    PS: Removed error handling and includes for ease of reading