Can';t force下载-PHP curl

Can';t force下载-PHP curl,php,curl,fopen,Php,Curl,Fopen,我们将一些数据导出为csv,并通过jQueryAjax表单提交触发它。我可以让它的基本工作,但我似乎不能得到的是强迫下载文件后,它的书面。 PHP 一如既往,我们非常感谢您的任何建议。泰。希望这能帮别人减轻我的头痛。以下是如何做到这一点(至少在我的情况下): 错误消息是什么?您如何确定您是否具有该文件或目录的写入权限?是否检查了目录/文件夹是否具有写入权限?可能是PHP,可能没有写入文件的权限。我在fireFTP>属性中添加了权限“0777”。我最适合调试它的方法是查看curl\u geti

我们将一些数据导出为csv,并通过jQueryAjax表单提交触发它。我可以让它的基本工作,但我似乎不能得到的是强迫下载文件后,它的书面。 PHP



一如既往,我们非常感谢您的任何建议。泰。

希望这能帮别人减轻我的头痛。以下是如何做到这一点(至少在我的情况下):


错误消息是什么?您如何确定您是否具有该文件或目录的写入权限?是否检查了
目录/
文件夹是否具有写入权限?可能是PHP,可能没有写入文件的权限。我在fireFTP>属性中添加了权限“0777”。我最适合调试它的方法是查看
curl\u getinfo()
我在转储curl信息时需要什么?
<?php
session_start();
echo $_SESSION['payerEmail'];
echo $_SESSION['password']; 
$url = 'http://www.ninjatrader-support2.com/sugar/FXCMLicense.php';
$FXCMAction = $_REQUEST["FXCMAction"];
$payerEmail = $_SESSION['payerEmail'];
$password = $_SESSION['password'];
$fields = array(
'FXCMAction'=>urlencode($FXCMAction),
'payerEmail'=>urldecode($payerEmail),
'password'=>urldecode($password)
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
$fields_string = rtrim($fields_string,'& ');

$ch = curl_init($url);
session_write_close();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
$directory='/home/ninja002/public_html/FXCMReports/';
$filename = 'XCMLicense.csv';
$handle = fopen($directory.$filename, 'w');
fwrite($handle, $output);
echo $output;
curl_close($ch);

?>
<?php
    session_start();
    $url = 'http://www.remotesite/script.php';
    $Foo = $_REQUEST["Foo"];
    $Bar = $_SESSION['Bar'];
    $password = $_SESSION['password'];
    $fields = array(
        'Foo'=>urlencode($Foo),
        'Bar'=>urldecode($Bar),
        'password'=>urldecode($password)
    );
    foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
    $fields_string = rtrim($fields_string,'& ');
    $ch = curl_init($url);
    session_write_close();
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($ch);
    curl_close($ch);
    $directory='/home/usr/public_html/Directory/';
    $filename = 'AwesomeData.csv';
    $handle = fopen($directory.$filename, 'w');
    fwrite($handle, $output);
    header('Content-type: application/octet-stream');
    header('Content-Disposition: attachment; filename="AwesomeData.csv"');
    echo $output;
?>