Derfder Derfder - 1 year ago 74
PHP Question

Get a filename from a string in PHP

I have this strings saved in my mysql database in format like:

/uploads/attachments/18/105/WordPress_3_Cookbook.pdf


Now, I need to get only the file name.

I guess I need some function in PHP that check the string from the backwards and get everything to the first slash.

How to write such thing?

Answer Source

You can use basename() this way

$filename = basename("/uploads/attachments/18/105/WordPress_3_Cookbook.pdf");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download