doujin8476 2018-11-06 12:46
浏览 45
已采纳

读取导致错误的图像文件 - 未捕获的ReferenceError

I am reading two image files and storing into psql. When I read one file, the code doesn't raise error. When I add code for other file, the code starts complaining 'Uncaught ReferenceError' about one script at the end of the html.

Here is my code. Is this correct way to read two image files or there is some problem the way I am trying to read the files.

if(isset($_POST["submit1"])){
    $file_name = $_FILES["img1"]["tmp_name"];
    $img = fopen($file_name, 'r') or die("cannot read image
"); 

    $data = fread($img, filesize($file_name));
    var_dump($file_name);

    $es_data = pg_escape_bytea($data);
    fclose($img);  

    $file_name2 = $_FILES["img2"]["tmp_name2"];
    $img2 = fopen($file_name2, 'r') or die("cannot read image
"); 

    $data2 = fread($img2, filesize($file_name2));
    var_dump($file_name2);

    $es_data2 = pg_escape_bytea($data2);
    fclose($img2);

    try {

        $sql .......................
  • 写回答

1条回答 默认 最新

  • douzhe1264 2018-11-06 12:54
    关注

    $_FILES is an multidimensional array. The first column/element represents the given file, the second an attribute corresponding to that file. So tmp_name will always stay the same while img will probably change. But you could also enter a 3rd dimension to handle multiple files.

    <form action="file-upload.php" method="post" enctype="multipart/form-data">
     Send these files:<br />
       <input name="userfile[]" type="file" /><br />
      <input name="userfile[]" type="file" /><br />
      <input type="submit" value="Send files" />
    </form>
    

    $_FILES["userfile"]["tmp_name"][0] would be the name of the first file, $_FILES["userfile"]["tmp_name"][1] the name of the second one, ...

    https://secure.php.net/manual/en/features.file-upload.multiple.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型