Solved

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

Posted on 2007-11-20
4
625 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
Comment Utility
$_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
Comment Utility
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
Comment Utility
Thanks man, I should have tried that earlier.  Appreciate it.
0
 
LVL 10

Expert Comment

by:wildzero
Comment Utility
:-) no problem, thanks for the points.

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to create an extensible mechanism for linked drop downs.
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.
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 …

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now