doupao6698 2018-05-25 18:37
浏览 34
已采纳

PHP多重上传 - 忽略上传代码

For my internship, I need to built a webapp using PHP, the goal of the application is to make notes using voice recognition technology (javascript).

One part of the "make-a-note" section is the ability to upload multiple images/files. The notes and images that are related are stored in 2 different tables, and are linked based on the NoteID.

  $countfiles = count($_FILES['images']['tmp_name']);
  $note_query = "INSERT INTO Notes(NOTS_ID, NOTS_V_USRS, NOTS_V_ORGS, NOTS_A_TITLE, NOTS_A_TEXT, NOTS_C_TAGS, NOTS_V_CTRY, NOTS_T_FROM, NOTS_T_UNTIL) VALUES ('0', '" . $usr_id['USRS_ID'] . "','" . $organisation . "', '" . $note_title .  "', '" . $note_text . "', '0', '" . $country . "', '" . $fromdate . "', '" . $untildate . "');";
   $conn->query($note_query) or die($conn->error());
   $lastid = $conn->insert_id;
  $imagedata  = array();
  // FILE UPLOAD 
  if (isset($_FILES['images'])){

    for($i=0; $i < $countfiles; $i++){
      $file_name = $_FILES['images']['name'][$i];
      $file_tmp = $_FILES['images']['tmp_name'][$i];
      array_push($imagedata, $file_name);
      $desired_dir="./uploads/imgs/";
       move_uploaded_file($file_tmp, $desired_dir.$file_name);
       $img_query = "INSERT INTO Images(IMGS_ID, IMGS_V_USRS, IMGS_T_NAME, IMGS_V_NOTS) VALUES ('0', '" . $usr_id['USRS_ID'] . "', '" . $desired_dir.$file_name . "', '" . $lastid . "');";
       $conn->query($img_query);
      }
  }

The part in the form where the file gets selected: <input type="file" name="images[] multiple">

When I fill in the form, and upload for example 2 images, it just skips over the code, meaning, no files get uploaded/inserted in the database. The "Note" part is added correctly.

Any suggestion on how come this does not work? Or what do I need to change?

Thanks alot!

Regards, Dries :)

EDIT enctype=multipart/form-data is also added

  • 写回答

1条回答 默认 最新

  • douzi6060 2018-05-25 18:39
    关注

    Did you put in the form enctype?

    <form enctype="multipart/form-data">
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题