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

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

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮