思路:后台点击上传,然后上传到指定位置,然后取得这个字符串写到数据库
<!--后台那边上传文件的标签代码-->
<form id="upload-form" action="" method="post" enctype="multipart/form-data" >
<input type="file" class="input-text" id="upload" name="upload" />
<input type="submit" class="btn btn-info" value="Upload" />
</form>
// 上传文件到指定目录,然后数据库保存路径
public function fileupload()
{
if (IS_POST) {
$file_size = $_FILES['upload']['size'];
if ($file_size > 20 * 1024 * 1024) {
echo "文件过大,不能上传大于20M的文件";
exit();
}
$dir = PACH."/Upload/sclass/";//文件目录 自己定义
$fileName = time().uniqid().'.'.pathinfo($_FILES["upload"]["name"])['extension'];
file_exists($dir) || (mkdir($dir,0777,true) && chmod($dir,0777));
move_uploaded_file($_FILES["upload"]["tmp_name"],$dir.$fileName);
$id = $_GET['id'];
$data['file'] = '/Upload/sclass/'.$fileName;
$this->_model->where('id=43')->save($data);
}
$this->display();
}
// 找到文件路径然后利用header方式进这个链接就下载
public function uploadpdf(){
$result = M('Information')->where('id=43')->field('file')->find();
$urlInfo = pathinfo($result['file']);
// 这边点不要忘了
$filePath = '.'.$result['file'];
$file = fopen($filePath, "r"); // 打开文件 // 输入文件标签
if ($file) {
Header("Content-type:application/pdf");
Header("Accept-Ranges: bytes");
Header("Accept-Length: " . filesize($filePath));
Header("Content-Disposition: attachment; filename=".$urlInfo['basename']); // 输出文件内容
echo fread($file, filesize($filePath));
fclose($file);
}
}
// 该二维码的直接输出
public function qrcode()
{
$url="http://".$_SERVER['SERVER_NAME']."/contact/uploadpdf.html";
$level=3;
$size=4;
Vendor('Phpqrcode.phpqrcode');
$errorCorrectionLevel =intval($level) ;//容错级别
$matrixPointSize = intval($size);//生成图片大小
//生成二维码图片
$object = new \QRcode();
$result = $object->png($url, false, $errorCorrectionLevel, $matrixPointSize, 2);
return $result;
}
<!--html标签直接调用这个方法就行了-->
<img src="/contact/qrcode.html" alt="">