Passing the name of a selected file to another text box

Posted on 2006-05-12
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
    LVL 70

    Accepted Solution


    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

    Okay, I'll try that thanks

    Author Comment

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

    Expert Comment

    by:Jason C. Levine
    No problem.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Adobe Photoshop CC 2015

    Photoshop has become the standard in image manipulation among professional photographers and graphic designers. This course covers exam objectives for the Adobe Certified Associate (ACA) certification.

    Suggested Solutions

    Title # Comments Views Activity
    Free website editor 10 544
    ColdFusion dropdown multiple select question 3 574
    Saving Form Data when Leaving Page 3 351
    Jquery submit form question 11 71
    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…
    This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    761 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

    12 Experts available now in Live!

    Get 1:1 Help Now