下载文件脚本

上一篇 / 下一篇  2017-06-11 18:18:13

web_url("download.php",
"URL=http://211.147.208.141/cn/resources/download.php?id=386",
"Resource=1",
"RecContentType=application/force-download",
"Referer=",
LAST);

Action()
{
 int flen;   //保存文件的大小
 long fileds;   //保存文件的句柄
 char FilePath[256]="\0"; //保存文件路径及名称

web_set_max_html_param_len("10000"); //设置页面接受的最大字节数,应大于下载文件的大小

web_concurrent_start(NULL);
 
 //关联文件内容
 web_reg_save_param("FileContent",
 "LB=",
 "RB=",
 "Search=BODY",
 LAST);

 //关联文件名。有些文件名是常量,所以无需关联
 web_reg_save_param("fileName",
 "LB=filename=\"",
 "RB=\"",
 "Search=all",
 LAST);
 
 //原内容,发出请求
 web_url("download.php",
 "URL=http://211.147.208.141/cn/resources/download.php?id=386",
 "Resource=1",
 "RecContentType=application/force-download",
 "Referer=",
 LAST);

 web_concurrent_start(NULL);

 //将路径追加给指针变量
 strcat(FilePath,"c:\\");
 //将文件名追加给指针变量。转换为字符串。
 strcat(FilePath,lr_eval_string("{FileName}"));

 //获得文件大小
 flen=web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE);

 if(flen > 0)
 {
  if((fileds = fopen(FilePath,"wb")) == NULL)
  {
   lr_output_message("Open File Failed");
   return -1;
  }
  fwrite(lr_eval_string("{FileContent}"),flen,1,fileds);
 }
 return 0;
}

如需重复保存文件到本地
char FilePath[256]="\0";
char *chNumber;

chNumber=lr_eval_string("{Random}"); //生成随机数

strcat(FilePath,"c:\\");
strcat(FilePath,chNumber);
strcat(FilePath,".rar");


TAG: 下载文件

 

评分:0

我来说两句

Open Toolbar