Solved

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

Posted on 2007-11-20
4
628 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
  • 2
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
wildzero earned 400 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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

803 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