Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用php在mysql中为一个id上载多个文件?_Php_Mysql - Fatal编程技术网

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

如何使用php在mysql中为一个id上载多个文件?,php,mysql,Php,Mysql,每次检查时,我都要将患者报告添加到其id。患者id已在数据库中。我要做的是添加他最近的报告并显示他以前的报告。这些报告可以是任何类似图像的文件,pdf等。我写了代码t它取代了以前的文件与新的,因为我使用上传查询。我如何添加多个文件 以下是用以前的文件替换新文件的代码: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Uploading

每次检查时,我都要将患者报告添加到其id。患者id已在数据库中。我要做的是添加他最近的报告并显示他以前的报告。这些报告可以是任何类似图像的文件,pdf等。我写了代码t它取代了以前的文件与新的,因为我使用上传查询。我如何添加多个文件

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

  <!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作为外键

每次在新表中上载新报告时插入数据


您可以将其链接到您的患者视图并相应地调用。

要维护以前报告的历史记录,您需要创建一个单独的报告表,并将患者id作为外键

每次在新表中上载新报告时插入数据


您可以将其链接到您的患者视图并相应地呼叫。

解决方案:

|id | file_name | file_data | patient_id | uploaded_at |
--------------------------------------------------------
为报告维护一个单独的表格,以帮助您相应地显示患者报告

报告\u表:

|id | file_name | file_data | patient_id | uploaded_at |
--------------------------------------------------------
这里是报表表的字段

文件名:上传文件的名称

文件\u数据:存储的文件路径

患者id:患者id

上传时间:上传日期时间

将报告存储在报告表中,根据患者id获取并显示报告

select * from reports_table where patient_id = patient_id

解决方案:

|id | file_name | file_data | patient_id | uploaded_at |
--------------------------------------------------------
为报告维护一个单独的表格,以帮助您相应地显示患者报告

报告\u表:

|id | file_name | file_data | patient_id | uploaded_at |
--------------------------------------------------------
这里是报表表的字段

文件名:上传文件的名称

文件\u数据:存储的文件路径

患者id:患者id

上传时间:上传日期时间

将报告存储在报告表中,根据患者id获取并显示报告

select * from reports_table where patient_id = patient_id

我只读了1行,但您是说我编写了用新文件替换先前文件的代码。这不是你的问题吗?你想保留过去的文件吗???而不是说你尝试插入了更新吗?这将只是放入一个新文件,而不是替换原来的COLLAM。请不要使用mysql,否则在您可以说“堆栈溢出”之前,您将被黑客攻击。将mysqli或pdo与准备好的语句和有界参数结合使用。你的上传模块也很弱。检查mime类型等。目前,特洛伊木马和其他有害文件可以轻松上载。我想保留以前的文件并上载新文件。好的,我将mysql添加到mysqli。我只读了1行,但你说我编写了用新文件替换以前文件的代码。这不是你的问题吗?你想保留过去的文件吗???而不是说你尝试插入了更新吗?这将只是放入一个新文件,而不是替换原来的COLLAM。请不要使用mysql,否则在您可以说“堆栈溢出”之前,您将被黑客攻击。将mysqli或pdo与准备好的语句和有界参数结合使用。你的上传模块也很弱。检查mime类型等。目前,特洛伊木马和其他有害文件可以轻松上传。我想保留以前的文件并上传新文件。好的,我将mysql上传到mysqli。