gpt4 book ai didi

php - 如何使用php在mysql中为一个id上传多个文件?

转载 作者:行者123 更新时间:2023-11-29 06:53:32 25 4
gpt4 key购买 nike

我想在每次检查时将患者报告添加到他们的 ID 中。患者 ID 已经在数据库中。我想做的是添加他最近的报告并显示他以前的报告。这些报告可以是任何文件,例如图像,pdf 等。我已经编写了代码,它会用新文件替换以前的文件,因为我正在使用上传查询。如何添加多个文件。

下面是用以前的文件替换新文件的代码:

  <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Uploading</title>
</head>
<body>
<h3 style="color:#28918f;" align='center'>PATIENT DETAILS</h3>
<?php
include 'dbcon.php';

if(isset($_GET['id']))
{
$id = $_GET['id'];
$sql="SELECT * FROM upload where patient_id='$id'";
$data = mysql_query($sql);
$row = mysql_fetch_array($data);?>
<table border='2' align='center'>
<tr><th>Patient Id</th>
<th>Doctor Id</th>
<th>File</th></tr>
<tr><td align='center'><?php echo $row['patient_id'];?></td>
<td align='center'><?php echo $row['doc_id'];?></td>
<td align='center'><?php echo $row['file'];?></td>
</tr>
</table>
<?php
if(isset($_POST['patient_id']))
{
$id=$_POST['patient_id'];
$file = $_FILES['file']['name'];
$file_loc = $_FILES['file']['tmp_name'];
$file_size = $_FILES['file']['size'];
$file_type = $_FILES['file']['type'];
$folder="uploads/";

$new_size = $file_size/1024
$new_file_name = strtolower($file);
$final_file=str_replace(' ','-',$new_file_name);
if(move_uploaded_file($file_loc,$folder.$final_file))
{
$sql1="UPDATE upload SET
file='$final_file',type='$file_type',size='$new_size' WHERE
patient_id='$id'";
mysql_query($sql1);
?>
<script>
alert('successfully uploaded');
window.location.href='fileupload.php?success';
</script>
<?php
}
else
{
?>
<script>
alert('error while uploading file');
window.location.href='fileupload.php?fail';
</script>
<?php
}
}
}
?>
<br /><br />
<?php
if(isset($_GET['success']))
{
?>
<label>File Uploaded Successfully...</a></label>
<?php
}
else if(isset($_GET['fail']))
{
?>
<label>Problem While File Uploading !</label>
<?php
}
else
{
?>
<?php
}
?>
</div>
</div>
</div>
</div>
<form action="" method="post" enctype="multipart/form-data">
<table align='center'>
<input type="hidden" name="patient_id" value="<?php
if(isset($_GET['id'])){ echo $_GET['id'] ; } ?>" >
<tr><td>Select a file</td> <td><input type="file" name="file" />
</td>
<td></td><td><button type="submit" name="btn-
upload">upload</button></td></tr>
</table>
</form>
</body>
</html>

最佳答案

解决方案:

维护一个单独的报告表,这将帮助您相应地显示患者报告,

报告表:

|id | file_name | file_data | patient_id | uploaded_at |
--------------------------------------------------------

这里是报告表的字段

file_name: Name of the file uploaded

file_data: Stored file path

patient_id: Patient id

uploaded_at: Uploaded date time

将报告存储在reports_table中,并根据病人id获取并显示它,

select * from reports_table where patient_id = patient_id

关于php - 如何使用php在mysql中为一个id上传多个文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46579126/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com