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
Solved

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

Posted on 2007-11-20
4
631 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

856 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