?
Solved

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

Posted on 2007-11-20
4
Medium Priority
?
640 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

765 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