title: How to get full filepath when uploading files in PHP?
body: <p>I really want to know how am I gonna get the full filepath when I upload a file in PHP?</p>
  
  <p>Here's my my problem...</p>
  
  <p>I am importing a csv file in PHP. Uploading a file isn't a problem but the function used to import csv files which is fgetcsv() requires fopen. fopen is the one giving me a headache because it requires an exact filepath which means that the file should be in the same directory with the php file. What if the user gets a file from a different directory.</p>
  
  <p>Here's my codes:</p>
  
  <p><b><code>index.php</code></b>:</p>
  
  <pre><code>&lt;form action="csv_to_database.php" method="POST" enctype="multipart/form-data"&gt;
   &lt;input type="file" name="csv_file" /&gt;
   &lt;input type="submit" name="upload" value="Upload" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><b><code>csv_import.php</code></b>:</p>
  
  <pre><code>&lt;?php
   if ($_FILES['csv_file']['error'] &gt; 0) {
    echo "Error: " . $_FILES['csv_file']['error'] . "&lt;br /&gt;"; 
   }else{ 
  
    if (($handle = fopen($_FILES['csv_file']['name'], "r")) !== FALSE) {
  
     while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
  
      for ($c=0; $c &lt; count($data) ; $c++) {
       echo $data[$c] . " ";
      }
      echo "&lt;br /&gt;";
     }
     fclose($handle);
    }
   }
  ?&gt;
  </code></pre>
  
  <p>fopen here can only get the filename which is passed  by the variable <code>$_FILES['csv_file']['name']</code>. I was trying to get any functions to get the full filepath for $_FILES in the internet but  can't find any. </p>
  
  <p>I am very new to web development so pls be patient. Pls answer as simple as possible... Pls help...</p>