title: PHP get file path of an image?
body: <p>Example:</p>
  
  <p>The image url:</p>
  
  <pre><code>localhost/example/folder/filename.jpg
  </code></pre>
  
  <p>I want to get path of the image so it must be:</p>
  
  <pre><code>localhost/example/folder/
  </code></pre>
  
  <p>How to do that?</p>
  
  <p><em><strong>I speak English not well. Thanks!</em></strong></p>
  
  <p>I have found a solution instead of using dirname:</p>
  
  <pre><code>$image = 'localhost/example/folder/filename.jpg';
  $directory = substr($image, 0, strrpos($image, '/', -2) + 1 );
  echo $directory;
  //return: localhost/example/folder/
  </code></pre>