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">
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路