【发布时间】:2015-01-30 15:13:10
【问题描述】:
我在一个目录中有 pdf 之类的文件,我创建了一个搜索表单,用户将在其中输入文件代码,如果它与文件名匹配,它将搜索源目录,如果不匹配,它将允许用户下载文件它将显示“无结果”这是我所做的,但我不确定应该使用什么代码从源目录下载文件,我只是看到了在某处下载文件并用变量 i 替换源文件的代码用户搜索时使用
<html>
<head>
<title>Search Contacts</title>
</head>
<body>
<h3>Search Client File</h3>
<form method="post" action="#" id="searchform">
Type the File Code:<br><br>
<input type="text" name="fcode">
<br>
<input type="submit" name="submit" value="Search">
</form>
<?php
$filecode=$_POST["fcode"];
if (!empty($filecode))
{
$ch = curl_init();
$source = "/sdir/$filecode.pdf";
curl_setopt($ch, CURLOPT_URL, $source);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec ($ch);
curl_close ($ch);
$destination = "/tdir/afile.pdf";
$file = fopen($destination, "w+");
fputs($file, $data);
fclose($file);
}
else
{
echo "No Results";
}
?>
</body>
</html>
【问题讨论】:
-
“它不起作用并且显示任何东西”是什么意思?你看到表格了吗,当它不起作用时会发生什么?错误消息,白页,没有结果?请再清楚一点。
-
$file="<sourcefile?>"这是什么意思? -
对不起,我现在已经编辑了我的问题,我真的不知道应该使用什么代码从我的源目录下载文件
标签: php html file search download