Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Passing the name of a selected file to another text box

Posted on 2006-05-12
Medium Priority
Last Modified: 2010-04-25
Hi All,
Making an admin area where I want to allow the user to upload an image file and put the file name into the database. I have the upload part working just need to know how to set a hidden variable on the page so that it gets the results of the selected file in the correct format. For example, the user might select a file with the path c:\windows\image1.jpg. In the hidden variable that is passed to the DB I only want the name of the file to be passed (as it is being uploaded so the dir is no longer needed). What statement do I have to write to just select the filename and not the path or directory?
Question by:dereksheahan
  • 2
  • 2
LVL 70

Accepted Solution

Jason C. Levine earned 1600 total points
ID: 16671201

When uploading a file, the local path info becomes irrelevant.  As long as this is version 4.1 of PHP or newer, there is a $_FILES array created and you extract anything you need from that array:



    The original name of the file on the client machine.


    The mime type of the file, if the browser provided this information. An example would be "image/gif". This mime type is however not checked on the PHP side and therefore don't take its value for granted.


    The size, in bytes, of the uploaded file.


    The temporary filename of the file in which the uploaded file was stored on the server.


    The error code associated with this file upload. This element was added in PHP 4.2.0

You should not try to reload the same form and rewrite the file name into a hidden form field...just process the $_FILES array and store whichever part you need in the table.

Author Comment

ID: 16671211
Okay, I'll try that thanks

Author Comment

ID: 16673903
Thanks Jason, as usual your spot on the mark.
LVL 70

Expert Comment

by:Jason C. Levine
ID: 16674450
No problem.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

For those who don't know, Adobe Dreamweaver is a popular commercial web editor that enables you to design, build and manage complex websites. The editor is a WYSIWYG (What You See Is What You Get) web editor, which means that you can create your web…
Adobe Dreamweaver CS5 is a WYSIWYG web page editor that has advanced HTML, CSS, and Javascript rendering functionality and is probably the most well-known HTML editor available. Much of Dreamweaver's appeal centers around the Design View interfac…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month15 days, 2 hours left to enroll

578 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