停止在页面加载时下载文件

时间:2012-06-23 22:45:51

标签: php forms

我有以下抓取器正在下载空文件并将其保存到我的文件夹中。所以我喜欢20k视频文件,每个都是40kb。我怎么能得到它所以这个脚本在形式提交之前不会DL。

$rename = substr(md5(rand(0,9999)), 17, 10); 
$ch = curl_init("$vid");
$fp = fopen("$rename.m4v", "w");

curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);
curl_close($ch);
fclose($fp);
$url_insert = "/dom/";

2 个答案:

答案 0 :(得分:1)

if(isset($_POST['some-form-item'])){

$rename = substr(md5(rand(0,9999)), 17, 10); 
$ch = curl_init("$vid");
$fp = fopen("$rename.m4v", "w");

curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);
curl_close($ch);
fclose($fp);
$url_insert = "/dom/";

}

仅当表格中贴有内容时才会运行,将顶部的if更改为任何项目正在posteD?

答案 1 :(得分:1)

<?

if(isset($_POST["submit"])) {

$rename = substr(md5(rand(0,9999)), 17, 10); 
$ch = curl_init("$vid");
$fp = fopen("$rename.m4v", "w");

curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);
curl_close($ch);
fclose($fp);
$url_insert = "/dom/";

}

为了使其正常工作,必须将提交按钮的name元素设置为submit。

即:<input type="submit" name="submit" />