在php中单击事件以检索可下载文件。

时间:2018-01-18 13:42:20

标签: javascript php http-proxy php-curl

我必须从网站下载csv文件。以前有一个表单动作网址,可以编程下载文件,但现在它是一个没有任何动作网址的选择按钮(只有'#')。并完全由JS操纵。当我点击'域名作为csv'然后csv文件将下载,但我想在脚本运行时这样做。每当我运行PHP脚本我可以访问和下载动作网址的帮助页面,但该特定文件不是检索。请知道如何处理这样的问题? enter image description here

php脚本:     

$proxy_host = "internet.com.ag";
$proxy_port = "1111";
$proxy = "$proxy_host:$proxy_port";
$teliko_credentials = array("username"=>"com", "pass"=>'com');
$url = '//domain.net/';
$url = '//domain.net/#';
//$url = /domain.net/#DomainOverview/Domains';
$fileExt = ".csv";
$file = '';
function curl_session($url, $proxy, $credentials ) {
    $ch = curl_init(); //init curl
    // snippet for via proxy authentication
    curl_setopt($ch, CURLOPT_URL, $url); //login form action url
    curl_setopt($ch, CURLOPT_PROXY, $proxy); // passing proxy details 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //If url has redirects then go to the final redirected URL.
    curl_setopt($ch, CURLOPT_POST, 1); // ENABLE HTTP POST
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'user='. $credentials['username'] .'&password='.urlencode( $credentials['pass'] ).'&submit=Login'); //Set the post parameters
    curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); //Handle cookies for the login
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //not to print out the results of its query. Instead, it will return the results as a string return value
    curl_exec($ch);
    curl_setopt($ch, CURLOPT_URL, $url);
    $file = curl_exec($ch); // retrieves the source file
    return $file;
    curl_close($ch);
}
$file = curl_session($url ,$proxy, $credentials);
if ($file != '')
    file_put_contents('\\W516014\Exchange\http\fs\Export-'.date("d.m.Y").$fileExt, $file);// download file into the specified directory 
?>

0 个答案:

没有答案