title: Prevent PHP file upload from shared network
body: <p>I have a file upload in PHP to a customer but because of their network is slow does it work bad when they upload from their network (it works well if they upload from ex their computer desktop).</p>
  
  <p>Can I prevent the user to select files from their network, and only allow from their own computer?</p>
  
  <p>I had a thought to only allow file path starting with network path, <code>\\</code> or <code>//</code> in the function <code>fileSelected()</code>. But due to security in new browsers, it is not possible to read the users upload path with JavaScript/jQuery because it is replaced with "fakepath".</p>
  
  <p>My script is a standard file upload in PHP.</p>
  
  <pre><code>&lt;div class="custom-file"&gt;
  &lt;input type="file" class="custom-file-input" id="fileToUpload" onchange="fileSelected();" name="fileToUpload" accept=".zip" required&gt;
  &lt;span id="selected-file" class="custom-file-label" for="fileToUpload"&gt;Choose file&lt;/span&gt;
  &lt;div class="invalid-feedback"&gt;
  Please select a file.
  &lt;/div&gt;
  &lt;/div&gt;
  
  function fileSelected() {
  //Calculate size
  }
  
  function uploadFile(fd) {
      fd.append("fileToUpload", document.getElementById('fileToUpload').files[0]);
      var xhr = new XMLHttpRequest();
      xhr.upload.addEventListener("progress", uploadProgress, false);
      xhr.addEventListener("load", uploadComplete, false);
      xhr.addEventListener("error", uploadFailed, false);
      xhr.addEventListener("abort", uploadCanceled, false);
      xhr.open("POST", "src/fileUpload.php");
      xhr.send(fd);
  }
  </code></pre>
  
  <p>fileUpload.php</p>
  
  <pre><code>&lt;?php
  //$fileName = $_FILES["fileToUpload"]["name"]; // The file name
  $fileName = $_SESSION['fileName'];
  $fileTmpLoc = $_FILES["fileToUpload"]["tmp_name"]; // File in the PHP tmp folder
  $fileType = $_FILES["fileToUpload"]["type"]; // The type of file it is
  $fileSize = $_FILES["fileToUpload"]["size"]; // File size in bytes
  $fileErrorMsg = $_FILES["fileToUpload"]["error"]; // 0 for false... and 1 for true
  
  move_uploaded_file($fileTmpLoc, "../uploads/$fileName")
  ?&gt;
  </code></pre>