How to get value of file type input in php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sachin Shah
    New Member
    • May 2007
    • 1

    #1

    How to get value of file type input in php

    [CODE=php]
    <?php ?>
    <html>
    <head>
    <script language="javas cript">
    function getpath()
    {
    var pname = document.form1. fr.value;
    return pname;
    }
    </script>
    </head>
    <body>
    <form enctype="multip art/form-data" name="form1" action="filerea d.php" method="POST">
    <input type="file" name="fr" id="fr"> <br><br>
    <input type="submit" name="submit" value="Read" >
    </form>

    <?php
    if(isset($_POST['submit']))
    {
    //$myfile="E:\sac hins\projects\m e\myfile.txt"; -This is static path
    $myfile= $_FILE["fr"]; //i want value of fr which is input file type
    echo $myfile;
    $fr=fopen($myfi le,"r");
    while (!feof($fr))
    {
    echo fgets($fr). "<br />";
    }
    ?>
    </body>
    </html>
    [/CODE]

    i am trying with above code to get the value input in file type in php code
    and not able to get this thing.
    i know how to take path in javascript
    but don't know how to pass that value to php code
    Please help me...
    Last edited by Atli; May 22 '07, 12:24 PM. Reason: Added code tags
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi, and welcome to TSDN.

    I am not entirly sure what you are trying to do. Please try to explain this a bit better so we can try to assist you.

    I am, however, going to take an educated guess, and say that you are trying to get some information about some file?

    If so you could try something like this:
    [CODE=php]
    <?php ?>
    <form enctype="multip art/form-data" action="?" method="POST">
    <input type="file" name="fr" id="fr"> <br><br>
    <input type="submit" name="submit" value="Read" >
    </form>

    <?php
    if(isset($_POST['submit']))
    {
    echo "<pre>";
    print_r($_FILES );
    echo "</pre>";
    }
    ?>
    [/CODE]

    Comment

    Working...