Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Displaying Filename Only When Using Custom Field File

Hello,

I'm adding a section to a site using a custom post that includes a field that allows users to upload files that can be downloaded by visitors to the site.

I've been trying to use:

            <?php $path = "this needs to be the path from the file upload field";


                echo basename($path) ."<br/>";
            ?>

But it displays nothing. If I add an actual fake folder and file reference in the quotes above it displays correctly in the browser. Just can't seem to access my upload field in the quotes.

Any help is welcome!

1 Answer

This is because the function basename takes a parameter of a file path and not a string... so like /etc/stuff/whatever would return whatever. It should not have spaces, and should be representing a path and not a string.