title: How to get relative path of uploaded file as variable in php (repost)
body: <p>How can I get the relative path to my uploaded file? For example if I upload test.png I would get /upload/test.png. Here is my HTML:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;title&gt;Jquery Ajax File Upload&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
      &lt;div class="col-sm-6"&gt;
          &lt;div class="form-group "&gt;
              &lt;label&gt;Profile image&lt;/label&gt;
              &lt;div class="input-group"&gt;
                  &lt;span class="input-group-addon"&gt;&lt;i class="fa fa-image"&gt;&lt;/i&gt;&lt;/span&gt; 
                  &lt;input type="text" class="form-control" name="profile_image" autocomplete="off" value="" placeholder="" &gt;
                   &lt;label class="btn btn-default btn-file input-group-addon"&gt;
      Browse &lt;input type="file" name="image" style="display: none;" onchange="myFunction()" id="image" &gt;
  &lt;/label&gt;
  &lt;div class="result"&gt;&lt;/div&gt;
  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"&gt;&lt;/script&gt;
      &lt;script&gt;
  
          $('#image').change(function(e){
              var file = this.files[0];
              var form = new FormData();
              form.append('image', file);
              $.ajax({
                  url : "http://192.168.1.147/upload.php",
                  type: "POST",
                  cache: false,
                  contentType: false,
                  processData: false,
                  data : form,
                  success: function(response){
                      $('.result').html(response.html)
                  }
              });
          });
  
      &lt;/script&gt;
  
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>PHP:</p>
  
  <pre><code>&lt;?php
  
  $file = $_FILES['image'];
  
  
  /* Allowed file extension */
  $allowedExtensions = ["gif", "jpeg", "jpg", "png", "svg"];
  
  $fileExtension = explode(".", $file["name"]);
  
  /* Contains file extension */
  $extension = end($fileExtension);
  
  /* Allowed Image types */
  $types = ['image/gif', 'image/png', 'image/x-png', 'image/pjpeg', 'image/jpg', 'image/jpeg','image/svg+xml'];
  
  if(in_array(strtolower($file['type']), $types) 
      // Checking for valid image type
      &amp;&amp; in_array(strtolower($extension), $allowedExtensions) 
      // Checking for valid file extension
      &amp;&amp; !$file["error"] &gt; 0)
      // Checking for errors if any
      { 
      if(move_uploaded_file($file["tmp_name"], 'uploads/'.$file['name'])){
          header('Content-Type: application/json');
          echo json_encode(['html' =&gt; /*return uploded file path and name*/ ]);    
          echo $_FILES['upload']['name'];
      }else{
          header('Content-Type: application/json');
          echo json_encode(['html' =&gt; 'Unable to move image. Is folder writable?']);    
      }
  }else{    
      header('Content-Type: application/json');
      echo json_encode(['html' =&gt; 'Please upload only png, jpg images']);
  }
  
  ?&gt;
  </code></pre>
  
  <p>The code works, that is upload the file but I don't know how to get the path back. The path may change because its for a user profile image and later I will change the upload path to one that is /$username. If you know how get the name only please post that anyway. Thanks in advance.</p>