• <bdo id='ELhCU'></bdo><ul id='ELhCU'></ul>
    1. <legend id='ELhCU'><style id='ELhCU'><dir id='ELhCU'><q id='ELhCU'></q></dir></style></legend>

      <small id='ELhCU'></small><noframes id='ELhCU'>

    2. <i id='ELhCU'><tr id='ELhCU'><dt id='ELhCU'><q id='ELhCU'><span id='ELhCU'><b id='ELhCU'><form id='ELhCU'><ins id='ELhCU'></ins><ul id='ELhCU'></ul><sub id='ELhCU'></sub></form><legend id='ELhCU'></legend><bdo id='ELhCU'><pre id='ELhCU'><center id='ELhCU'></center></pre></bdo></b><th id='ELhCU'></th></span></q></dt></tr></i><div id='ELhCU'><tfoot id='ELhCU'></tfoot><dl id='ELhCU'><fieldset id='ELhCU'></fieldset></dl></div>
      <tfoot id='ELhCU'></tfoot>

        如何获取html中的文件路径<input type="file&q

        时间:2023-05-20
          <bdo id='GdXfc'></bdo><ul id='GdXfc'></ul>
        • <i id='GdXfc'><tr id='GdXfc'><dt id='GdXfc'><q id='GdXfc'><span id='GdXfc'><b id='GdXfc'><form id='GdXfc'><ins id='GdXfc'></ins><ul id='GdXfc'></ul><sub id='GdXfc'></sub></form><legend id='GdXfc'></legend><bdo id='GdXfc'><pre id='GdXfc'><center id='GdXfc'></center></pre></bdo></b><th id='GdXfc'></th></span></q></dt></tr></i><div id='GdXfc'><tfoot id='GdXfc'></tfoot><dl id='GdXfc'><fieldset id='GdXfc'></fieldset></dl></div>

                <tbody id='GdXfc'></tbody>

              1. <legend id='GdXfc'><style id='GdXfc'><dir id='GdXfc'><q id='GdXfc'></q></dir></style></legend>

                <small id='GdXfc'></small><noframes id='GdXfc'>

                • <tfoot id='GdXfc'></tfoot>

                • 本文介绍了如何获取html中的文件路径<input type="file">在 PHP 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  谁能告诉我如何在 PHP 中使用 html <input type="file"> 获取文件路径?

                  Can somebody pls tell me how to get the filepath using html <input type="file"> in PHP?

                  这是我的代码:

                  index.php

                  <form action="csv_to_database.php" method="get" >
                   <input type="file" name="csv_file" />
                   <input type="submit" name="upload" value="Upload" />
                  </form>
                  

                  csv_to_database.php

                  <?php
                  
                   if (isset($_GET['csv_file'])) {
                  
                   $row = 1;
                  
                    if (($handle = fopen($_GET['csv_file'], "r")) !== FALSE) {
                     while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
                      $num = count($data);
                      echo "<p> $num fields in line $row: <br /></p>
                  ";
                      $row++;
                      for ($c=0; $c < $num; $c++) {
                          echo $data[$c] . "<br />
                  ";
                      }
                     }
                     fclose($handle);
                    }
                  
                   } 
                  ?>
                  

                  我的问题是,它仅在 csv 数据与我的 php 文件位于同一目录中时才有效.我想我需要获取文件路径,但我不知道该怎么做.

                  My problem is, it only works when the csv data is in the same directory as my php files. I think I need to get the file path but I don't know how to do it.

                  推荐答案

                  你不应该只使用你现在拥有的 $_GET.您的文件基于 $_FILES["csv_file"]["tmp_name"].

                  You shouldn't just use the $_GET you've got now. Your file is based in $_FILES["csv_file"]["tmp_name"].

                  最好阅读本教程,基本上说你需要做这样的事情:

                  Best you review this tutorial, that basically says you need to do something like this:

                  <?php
                  if ($_FILES["csv_file"]["error"] > 0)
                    {
                    echo "Error: " . $_FILES["csv_file"]["error"] . "<br />";
                    }
                  else
                    {
                    echo "Upload: " . $_FILES["csv_file"]["name"] . "<br />";
                    echo "Type: " . $_FILES["csv_file"]["type"] . "<br />";
                    echo "Size: " . ($_FILES["csv_file"]["size"] / 1024) . " Kb<br />";
                    echo "Stored in: " . $_FILES["csv_file"]["tmp_name"];
                    }
                  ?>
                  

                  你可以从那里去.如果您想从临时位置移动文件,请使用 move_uploaded_file,教程中也有说明:)

                  And you can go from there. Use move_uploaded_file if you want to move the file from the temp location, also explained in the tutorial :)

                  这篇关于如何获取html中的文件路径<input type="file">在 PHP 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:文件太大时上传不正确 下一篇:使用 PHP 创建单文件上传表单的最佳方法是什么

                  相关文章

                  最新文章

                  <small id='2koSW'></small><noframes id='2koSW'>

                  • <bdo id='2koSW'></bdo><ul id='2koSW'></ul>
                  1. <i id='2koSW'><tr id='2koSW'><dt id='2koSW'><q id='2koSW'><span id='2koSW'><b id='2koSW'><form id='2koSW'><ins id='2koSW'></ins><ul id='2koSW'></ul><sub id='2koSW'></sub></form><legend id='2koSW'></legend><bdo id='2koSW'><pre id='2koSW'><center id='2koSW'></center></pre></bdo></b><th id='2koSW'></th></span></q></dt></tr></i><div id='2koSW'><tfoot id='2koSW'></tfoot><dl id='2koSW'><fieldset id='2koSW'></fieldset></dl></div>
                    <legend id='2koSW'><style id='2koSW'><dir id='2koSW'><q id='2koSW'></q></dir></style></legend>
                    <tfoot id='2koSW'></tfoot>