我想每次去检查时都要将患者报告添加到他们的ID中。患者ID已经在数据库中。我想要做的是添加他最近的报告并显示他以前的报告。这些报告可以是任何文件,如图像,pdf等我已经写了代码t它用新的替换以前的文件,因为我使用上传查询。我如何添加多个文件。如何使用php在mysql中上传一个id的多个文件?
下面是更换新的文件与以前的代码:
<!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>
我只读了1行,但你说我已经编写了用新文件替换以前的文件的代码。这不是你的问题是你想保持过去的文件? – Tomm
而不是说更新你尝试插入?这将只是放入一个新文件,而不是替换原始的collum。 – Tomm
请不要使用mysql_ *,否则在你说'堆栈溢出'之前你会被黑客入侵。将mysqli或pdo与预准备语句和有界参数结合使用。你的上传模块也很薄弱。检查MIME类型等。目前,木马和其他有害文件可以很容易地上传。 – Akintunde007