Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2007-11-20
4
Medium Priority
?
643 Views
Last Modified: 2010-04-21
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?
0
Comment
Question by:parlays
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
wildzero earned 1600 total points
ID: 20324305
$_FILES['newpic']['name'] ? where 'newpic' is the name of my form field
(also - $_FILES['newpic']['tmp_name'] holds the temp file name)
like

<input name='newpic' type='file' value=''>

U should be able to do an print_r($_FILES); which would show you the $_FILES array which is populated from a form after submission when you have a type='file'

0
 

Author Comment

by:parlays
ID: 20324444
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.
0
 

Author Closing Comment

by:parlays
ID: 31410256
Thanks man, I should have tried that earlier.  Appreciate it.
0
 
LVL 10

Expert Comment

by:wildzero
ID: 20324948
:-) no problem, thanks for the points.

0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question