0

我有一个表单,可以将包含其他信息的文件上传到数据库并将其显示在图表中。现在图表只显示文件名而不链接它。如果文件名为 test1.pdf,我将如何在图表上显示它仍然显示 chart1.pdf 但将其链接到文件所在的目录?

                       if ('POST' === $_SERVER['REQUEST_METHOD'])
{
$con = mysql_connect("localhost","xxxx","xxxxx");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("jjlliinn_test", $con);


$target = "clientdoc/"; 
$target = $target . basename( $_FILES['file']['name']);

$date = $_POST['date'];
$propertydescription = $_POST['propertydescription'];
$transactiontype = $_POST['transactiontype'];
$applicabledocument = ($_FILES['file']['name']); 
$received = $_POST['received'];
$paid = $_POST['paid'];

//Writes the to the server 
 if(move_uploaded_file($_FILES['file']['tmp_name'], $target)) 
 { 

 //Tells you if its all ok 
 echo ""; 
 } 
 else { 

 //Gives and error if its not 
 echo "Sorry, there was a problem uploading your file."; 
 } 

$sql = mysql_query("INSERT INTO `transactions` (`date`, `agentclient`, `propertydescription`, `transactiontype`, `applicabledocument`, `received`, `paid`) 
VALUES
 ('$date', '$agentclient', '$propertydescription', '$transactiontype', '$applicabledocument', '$received', '$paid')") or die(mysql_error()); 
$query = mysql_query($sql);
if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
echo "Succesfully added transaction. Updating table...";
echo "<META HTTP-EQUIV=\"refresh\" CONTENT=\"48\">";
mysql_close($con);
}
}
?>
4

1 回答 1

0

假设您所有的上传都存储在客户端文档文件夹中,并且您已经运行查询以从事务表中获取记录集...

<a href="/clientdoc/<?php echo $applicabledocument; ?>" title="example title">link text</a>

另一点,查看代码,将原始 $_POST 值直接发送到数据库是在询问 sql 注入问题。查看设置了 ENT_QUOTES 的 htmlentities 或 php 可用的输入过滤器。

于 2013-06-04T09:42:55.117 回答