[英]Downloading a file using php
I uploaded a PDF file to a folder called 'forms' on my webserver. 我将PDF文件上传到Web服务器上名为“ forms”的文件夹中。
I'm displaying data from my database onto a table, and the forms column I want to link to the file associated within the forms directory. 我正在将数据库中的数据显示在表上,并且要链接到forms列中的forms目录中的forms列。
I've currently got the following; 我目前有以下内容;
while ($myrow = mysqli_fetch_array($result)):
$loanid = $myrow["loanid"];
$username = $myrow["username"];
$form = $myrow["form"];
$table = '<tr>';
$table.= '<td>'.$loanid.'</div>';
$table.= '<td>'.$username.'</div>';
$table.= '<td><a href=\"forms/$form\">'.$form.'</a></div>';
echo $table
endwhile;
The table is displaying correctly and the correct file name is displaying in the forms column. 该表显示正确,并且在窗体列中显示正确的文件名。 However when I click the link it doesn't open the PDF as expected.
但是,当我单击链接时,它没有按预期打开PDF。
When I click the link I would imagine the link should be; 当我单击链接时,我会想到该链接应该是; www.example.com/website/forms/form.pdf
www.example.com/website/forms/form.pdf
but im receiving an object not found page and the following link; 但是我收到一个找不到对象的页面和以下链接; www.example.com/"forms/$loanform/"
www.example.com/“表格/ $ loanform /”
What am I doing wrong? 我究竟做错了什么?
Single quotes does not evaluate variables and you don't need to escape double quotes in them. 单引号不会计算变量,也不需要在其中转义双引号。
Use either 使用任一
$table.= "<td><a href=\"forms/$form\">".$form."</a></div>";
or 要么
$table.= '<td><a href="forms/' . $form . '">' . $form . '</a></div>';
Try the below code, In your your closing with it should be and you need to use " instead of ' when you are using php varibales in between 尝试下面的代码,在结束时应该是,当您在之间使用php自变量时,需要使用“而不是”
<?php
$table = "<table>";
while ($myrow = mysqli_fetch_array($result)):
$loanid = $myrow["loanid"];
$username = $myrow["username"];
$form = $myrow["form"];
$tr = '<tr>';
$tr.= '<td>'.$loanid.'</td>';
$tr.= '<td>'.$username.'</td>';
$tr.= "<td><a href=\"forms/$form\">".$form."</a></td>";
$tr .= "</tr>";
$table .= $tr;
endwhile;
$table .= '</table>';
echo $table
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.