cURL文件上载在Windows 2012 R2上运行的PHP 5.6.x中不起作用

时间:2015-12-16 18:18:16

标签: php curl

我使用以下代码使用.NET上传脚本将文件上传到服务器:

    if(isset($_FILES['fileToUpload'])) {
        $url = "path/to/FileUpload.aspx";  // request URL
        $filename = $_FILES['fileToUpload']['name'];
        $filedata = $_FILES['fileToUpload']['tmp_name'];
        $filesize = $_FILES['fileToUpload']['size'];
        $filetype = $_FILES['fileToUpload']['type'];
        
        if ($filedata != '') {
            
            $dom = dom_import_simplexml($response);
            $processXML = $dom->ownerDocument->saveXML($dom->ownerDocument->documentElement);
            
            $params = $companyId.",".$userId.",".$dataXML;
            $headers = array("Content-Type:multipart/form-data"); // cURL headers for file uploading
            
            $ch = curl_init();
            
            $file = new CURLFile($filedata,$filetype,$filename);
            
            $postfields = array("file" => $file,"params" => $params);
            
            $options = array(
                CURLOPT_URL => $url,
                CURLOPT_PORT => 8085,
                CURLOPT_SSL_VERIFYPEER => false,
                CURLOPT_SSL_VERIFYHOST => false,
                CURLOPT_SAFE_UPLOAD => false,
                CURLOPT_HEADER => true,
                CURLOPT_POST => 1,
                CURLOPT_HTTPHEADER => $headers,
                CURLOPT_POSTFIELDS => $postfields,
                CURLOPT_INFILESIZE => $filesize,
                CURLOPT_RETURNTRANSFER => true
            ); // cURL options
            
            curl_setopt_array($ch, $options);
            $result = curl_exec($ch);
            
            $info = curl_getinfo($ch);
            
            $http_code = $info['http_code'];
            
            if(!curl_errno($ch)) {
                if ($http_code == 200) {
                    
                    echo "File uploaded successfully<br>";
                    
                    // If file uploaded successfully, post the question...
                    postQuestion($arg1,$arg2);
                    
                } else {
                    $arr = array('status' => 'error', 'message' => 'http error');
                }
            } else {
                $arr = array('status' => 'error', 'message' => 'upload error');
                echo json_encode($arr);
            }
            
            curl_close($ch);
        } else {
            echo "Invalid file";
        }
    }

问题

脚本始终返回array('status' => 'error', 'message' => 'upload error');

这个代码适用于Apache(xampp)。

我检查了服务器上的所有配置(php.ini,必需的.dll),一切似乎都是有序的。

此处和其他地方的一些帖子建议将ssleay.dlllibeay.dll从PHP安装目录复制到Windows\System32。也试过了。

curl_error($ch)不返回任何内容

curl_errno($ch)返回43

环境详情

  • Windows 2012 R2
  • PHP v5.6.0
  • cURL v7.36.0

我在这里缺少什么?我刚刚开始学习PHP 2周,所以请保持温和:)

0 个答案:

没有答案