How to get the file path in html <input type=“file”> in PHP?

泪湿孤枕 提交于 2019-11-27 09:44:27

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"];
  }
?>

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 :)

I think you would gain a lot from taking a look at the following link: POST method uploads.

First of all, you should change your form method to post, and add enctype="multipart/form-data".

Then you can get the temporary file path from $_FILES['csv_file']['tmp_name'].

David Fells

In your call to fopen, use $_GET['csv_file']['tmp_name'] - this points to the file on the server immediately after upload.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!