Link to home
Start Free TrialLog in
Avatar of parlays
parlays

asked on

Getting file name for uploaded file from hard drive using PHP basename function?

Using PHP to receive an upload file from a file input form element.

Want to get the filename by using the basename function but the function doesn't work when the path starts with the drive letter (for example, c:\documents\test.txt), it can't get me the test.txt information.

I would try to use the explode function to create an array but the directory system on Macs and PCs are different.  Can someone tell me how to get the file name off a mac or PC.  Is it possible to use basename?
ASKER CERTIFIED SOLUTION
Avatar of wildzero
wildzero

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of parlays
parlays

ASKER

Yes!  I should have tried that.  Got caught up in using code from PHP.net site and trying to make that work instead of just using the FILES array.  Ocurred to me earlier but not sure why I didn't try it.

I think I figured out what was happening with basename function.  I was uploading from my PC using Windows but then the basename function was being executed on the server which is Linus Apache and the basename function wouldn't work with backslashes.

Thanks for the response buddy.
Avatar of parlays

ASKER

Thanks man, I should have tried that earlier.  Appreciate it.
:-) no problem, thanks for the points.