Displaying the contents of FileField in a form via PHP when redisplayed due to validation failure

Posted on 2007-07-28
Last Modified: 2012-05-05
In PHP when you are processing a form and don't get the right answers or have missing fields and redisplay the form using value=$_POST['fieldname'] to display the information which was entered before, how do you display the filename which was entered into a FileField?
Question by:Computer_Dilo
    LVL 48

    Expert Comment

    Thats not possible. The value of <input type="file"> is neither writeable via HTML nor via JS, only via user interactions. THis is due security reasons as else forms could steal files from the user without permisions of the user.
    LVL 49

    Expert Comment

    A solution might be to implement additional Javascript form validation, such that the missing fields are detected clientside.
    Note that this should not replace your serverside validation as not everyone might have javascript enabled.


    Author Comment

    That's what I thought hernst42 - except I didn't know why exactly (thanks). So would there be another way with a normal text field used to load a file using PHP code??
    LVL 48

    Accepted Solution

    You could save the submitted file, if not all fields are filled to  a temporay location on the server, add a marker in a hidden field and if the form is resubmitted, all fields filled use the temp-file instead of the file from $_FILES. That will require that you clean up the temp-directory for leftover files, where the form has not submitted again.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Suggested Solutions

    This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
    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 …

    746 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

    16 Experts available now in Live!

    Get 1:1 Help Now