doingword.com

Get the name of the file using substr

December 10th, 2007

Hi guys,
Here the php code to get the actual name of the file. This is very usefull when you need to get the name of the file and you only have the full path like /download/games/getfile.php. To get the name I use the $_SERVER[”PHP_SELF”] var.
Here the code:

  1. $file = substr(strrchr($_SERVER["PHP_SELF"],"/"),1);

If $_SERVER[”PHP_SELF”] is /download/games/getfile.php the value of $file is getfile.php
Yes, I know, it’s very simple, but (at least for me) very usefull

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Entry Filed under: Php, tip


Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed