How to save images to a remote image server using PHP?

Discussion in 'PHP' started by Grant37, Oct 21, 2013.

  1. #1
    Hi everybody.

    I have never built a website that needed a remote image server but I want this current project to scale if necessary. My hosting company is much more affordable than any cloud hosting offering so I simply want to set up my own image server(s). My question is what is the best way to save the images to a remote image server (linux) using PHP? CURL, FTP, POST, file_put_contents, sockets? I'm pretty sure I could use one or several of these methods. I'm just not sure which way is recommended.

    Grant
     
    Grant37, Oct 21, 2013 IP
  2. mladenbl

    mladenbl Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #2
    Hi, I suggest you to use SSH2, for me that was the best way to communicate with remote linux servers.
     
    mladenbl, Oct 21, 2013 IP
  3. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #3
    Question: if these servers are cohost on same location, why not just use Linux built in functions to create a fail over backup of the image hosting? No need to create any kind of php potentially creating security issues, just set up a cron job to copy across internal network and delete the files uploaded to the production server.
     
    PoPSiCLe, Oct 21, 2013 IP
  4. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #4
    I would use SSHFS or SFTP to mount the hard drive on your server. So to your server, you will be writing the data to /locationx.
     
    ThePHPMaster, Oct 21, 2013 IP
  5. Grant37

    Grant37 Active Member

    Messages:
    64
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    58
    #5
    thanks everybody for the input. i like these ideas. if anyone has an opinion on it feel free to comment.
     
    Grant37, Oct 21, 2013 IP
  6. Meglepett

    Meglepett Active Member

    Messages:
    152
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #6
    I would use Curl.

    $ch = curl_init("http://www.remotepage.com/upload.php");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CUROPT_POSTFIELDS, array('fileupload' => '@'.$_FILES['theFile']['tmp_name']));
    echo curl_exec($ch); 
    Code (markup):
    At the remote server php should write the file out and respond with full url of the location. Then at local server I would write the url to sql.
     
    Meglepett, Oct 22, 2013 IP
  7. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #7
    Why would you use external bandwidth when the servers seemingly are on the same network, or at least the same location, and should be able to communicate via way faster LAN?
     
    PoPSiCLe, Oct 22, 2013 IP
  8. Grant37

    Grant37 Active Member

    Messages:
    64
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    58
    #8
    Fair point PoPSiCLe. I'm sure there are people wondering how to do this with servers that are off of the local network as well. Those people will appreciate Meglepett's comment.
     
    Grant37, Oct 22, 2013 IP