Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php cURL-无法将文件从服务器1发送到服务器2_Php_Apache_Curl_Ftp_File Transfer - Fatal编程技术网

Php cURL-无法将文件从服务器1发送到服务器2

Php cURL-无法将文件从服务器1发送到服务器2,php,apache,curl,ftp,file-transfer,Php,Apache,Curl,Ftp,File Transfer,我在aws上有2台服务器。我正在尝试将文件从服务器1移动到服务器2。这是我在server1上的代码- function moveFileToServer2($filepath, $target_url){ $cFile = null; if (function_exists('curl_file_create')) { $cFile = curl_file_create($filepath); } else {

我在aws上有2台服务器。我正在尝试将文件从服务器1移动到服务器2。这是我在server1上的代码-

function moveFileToServer2($filepath, $target_url){
        $cFile = null;
        if (function_exists('curl_file_create')) {
            $cFile = curl_file_create($filepath);
        } else {
            $cFile = '@' . realpath($filepath);
        }
        if($cFile != null){
            $post = array('file_contents'=> $cFile);
            try{
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $target_url);
                curl_setopt($ch, CURLOPT_HEADER, false);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLOPT_POST, true);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
                curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
                $result = curl_exec ($ch);
            }catch(Exception $e){
                 //catch exception
            }finally{
                curl_close ($ch);
            }
            return $result;
        }
    }
所有文件路径都是正确的(绝对和相对)。我已经核实过了

这是我在server2上的代码(curl\u file\u receiver.php)-

无论哪种方式,我都没有在服务器2上收到任何文件。这段代码在我的本地机器上运行良好。(即,如果我将文件从一个应用程序发送到同一个XAMPP服务器上的另一个应用程序)(每个服务器托管一个PHP项目) 有人能告诉我出了什么问题吗?我需要在aws服务器上启用curl/php设置吗?还是我需要设置一些卷曲选项


另外,我需要能够在我的生产服务器上通过https发送文件,我已经关闭了CURLOPT_SSL_VERIFYPEER。一个可以通过https发送文件的解决方案将对我有很大帮助。

你希望人们阅读很多代码。有关编写好问题的提示,请参阅:。抱歉,根据要求,我编辑了代码。你能给我指一下正确的方向吗。
<?php
    //some other stuff here         
    $output_dir = "../uploads/";

    move_uploaded_file($_FILES["file_contents"]["tmp_name"], $output_dir);
    echo json_encode(1);
    exit;
?>
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href="https://<server-path>/curl_file_receiver.php?<some-other-params>"here</a>.</p>
<hr>
<address>Apache/2.4.7 (Ubuntu) Server at -server-name- Port 80</address>
</body></html>