简体   繁体   中英

How to send file in PHP 5.05 using cURL

I'm trying to send a file in PHP 5.0.5 using cURL but cannot do it. It returns bool(false). I can send it using command line but I need to send it within my PHP code.

THis is the commandline code, curl --data-binary @employee_extract.txt https://testserver.com/testapp.aspx --proxy http://111.111.11.11:8080

This is the successful returned message,

<?xml version="1.0"?>
<Status>
  <result>ok</result>
  <size>192</size>
  <id>20190409134142_C12040C53BCC4AC6B4A09E1BC476D262.txt</id>
  <message>
    <p>file</p>
    <p>No xmldoc posted, saving stream.</p>
  </message>
</Status>

PHP Code:

$url = 'https://testserver.com/testapp.aspx';
$proxy = '111.111.11.11:8080';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);

// send a file
curl_setopt($ch, CURLOPT_POST, true);
$args['file'] = "@employee_extract.txt;filename=file;type=text/plain"   
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);    
echo $curl_scraped_page;
var_dump($curl_scraped_page);

actual results: var_dump($curl_scraped_page) returns bool(false) expected results: a successful message

You are using a version of PHP that reached end-of-life in 2005, nearly 15 years ago. Your problem is probably related to this. For instance, your example URL uses HTTPS -- it's possible that the version of curl embedded in your vintage PHP interpreter is incompatible with the HTTPS configuration of the web server it is connecting to.

(Even if "5.0.5" is a typo and you actually meant PHP 5.5, that version reached end-of-life in 2016.)

Update your system to a supported version of PHP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM