繁体   English   中英

如何在mysql表中自动链接上载

[英]How can I have a upload auto linked in a mysql table

我有一个将其他信息的文件上传到数据库并在图表中显示的表单。 现在,该图表仅显示文件名,并且不链接它。 如果该文件名为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);
}
}
?>

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

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

另一点,看一下代码,直接将原始$ _POST值发送到db询问SQL注入问题。 看看设置了ENT_QUOTES的htmlentities或php可用的输入过滤器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM