Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

Only show the file name on all files instead of the full file path

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The user uploads their certificate files on a form and once submitted the full file path is displayed on a new page.

So instead of seeing /Documents/Certificates/2019/Level-1-Rigger.pdf, I need it to just show Level-1-Rigger.pdf

I've looked around and found that using basename() does the job but only found examples where the file path has to be entered:

However I can't do this for hundreds of files with new ones getting uploaded all the time. Is there a way shorten the path files to the basename globally for every file.

Saloon Keeper
Posts: 22122
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, Ed!

Have you actually tried using basename() on a short (relative) path?
Saloon Keeper
Posts: 12022
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

First of all, you don't want to be mixing presentation and business logic. Use a template language to create the pages where you display the file names.

When you've created your template, you can render a view by passing it the data that needs to be displayed by the template. Pass it the array of file names, and let the template render them in a for-loop.

In your business logic, if you have an array of file paths, you can convert the array to a different array that contains only the file names. Use the array_map() function for this:
When all four tires fall off your canoe, how many tiny ads does it take to build a doghouse?
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic