doingword.com

Archive for December, 2007

Get the name of the file using substr

Monday, 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]

Posted in Php, tip | No Comments »