Posted By

sarfraznawaz2005 on 11/27/08


Tagged

url filename


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

sidisinsane
jeremyhcobb


Gets filename from current URL


 / Published in: PHP
 

Gets filename from current URL

  1. // function to get current filename from a url made by sarfraz ahmed.
  2. function get_url_filename()
  3. {
  4. $filename = array_pop(explode("/",$_SERVER['REQUEST_URI']));
  5. $ext = substr($filename,strpos($filename,"."));
  6.  
  7. if (substr($ext,4))
  8. {
  9. if (substr($ext,4,1)=="?")
  10. {
  11. $ext = substr($ext,0,4);
  12. }
  13. else
  14. {
  15. $ext = substr($ext,0,5);
  16. }
  17. }
  18.  
  19. $filename = substr($filename,0,strpos($filename,"."));
  20.  
  21. return $filename . $ext;
  22. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: mahender on December 2, 2008

Good Job!

function geturlfilename($turl = '') { if($turl == '') { $turl = $SERVER['REQUESTURI']; } $filename = array_pop(explode("/", $turl)); $ext = substr($filename,strpos($filename,"."));

if (substr($ext,4))
{
    if (substr($ext,4,1)=="?")
    {
        $ext = substr($ext,0,4);
    }
    else
    {
        $ext = substr($ext,0,5);
    }
}

$filename = substr($filename,0,strpos($filename,"."));  

return $filename . $ext;

}

You need to login to post a comment.