将图像上传到远程服务器。 PHP

问题描述:

我做图像托管和我有一个问题..将图像上传到远程服务器。 PHP

我有3台服务器。

首先 - 网站/脚本

对图像的任何两个服务器。

如何将图像从“一个”服务器(脚本)上传到第二个和第三个服务器?

<?php 
    if (isset($_POST['upload'])) 
    { 
     $blacklist = array('.php', '.phtml', '.php3', '.php4', '.php5'); 
     foreach ($blacklist as $item) 
     { 
      if(preg_match('#' . $item . '\$#i', $_FILES['file']['name'])) 
      { 
       echo "We do not allow uploading PHP files\n"; 
       exit; 
      } 
     } 

     $uploadDir = PROJECT_ROOT . 'upload/'; // 1ST SERVER (THIS SERVER) 
     $uploadFile = $uploadDir . basename($_FILES['file']['name']); 

     if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadFile)) 
     { 
      echo "File is valid, and was successfully uploaded.\n"; 
     } 
     else 
     { 
      echo "File uploading failed.\n"; 
     } 
    }  
?> 
<form name="upload" method="post" enctype="multipart/form-data"> 
    Select the file to upload: <input type="file" name="file"/> 
    <input type="submit" name="upload" value="upload"/> 
</form> 
+0

你想在这里实现什么?您是否尝试在三台服务器上同步图像,或? – 2011-01-23 18:01:42

+0

@middaparka,我做图像托管。当你加载一张图片时,它应该被倒在3台服务器中的任何一台上。 3台服务器需要卸载该通道。稍后会有更多的服务器。 – Isis 2011-01-23 18:08:39

您可以使用ftp。 PHP有相当简单的方法来做到这一点。检查这个链接。

http://www.php.net/manual/en/book.ftp.php

如果你已经有HTTP服务器,乳宁在其他服务器上,使用cURL。用法:

  1. 呼叫curl_init
  2. 呼叫curl_setopt
  3. 呼叫curl_exec

HTTP请求可使用curl_setopt进行配置。特别感兴趣的是选项CURLOPT_URL,CURLOPT_POST和CURLOPT_POSTFIELDS。

您可以使用Zend_Http客户端将文件上传到其他服务器,每个HTTP的方式与HTML上载表单执行操作的方式相同。你可以找到你需要在这里的部分“文件上传”的所有信息:http://www.zendframework.com/manual/en/zend.http.client.advanced.html

入门的你也应该阅读:

http://www.zendframework.com/manual/en/zend.http.client.html

基本上你需要的代码是:

require_once('Zend/Http/Client.php'); 
$client = new Zend_Http_Client("http://serverurl/path"); 
$client->setFileUpload(...); 
$client->request();