By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,461 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

How to get value of file type input in php

P: 1
Expand|Select|Wrap|Line Numbers
  1. <?php ?>
  2. <html>
  3.     <head>
  4.        <script language="javascript">
  5.             function getpath()
  6.     {
  7.     var pname = document.form1.fr.value;
  8.     return pname;
  9.     }
  10.        </script>
  11.      </head>
  12.      <body>
  13.             <form enctype="multipart/form-data" name="form1" action="fileread.php" method="POST">
  14.                      <input type="file" name="fr" id="fr"> <br><br>
  15.          <input type="submit" name="submit" value="Read" >
  16.              </form>
  17.  
  18.         <?php
  19.                 if(isset($_POST['submit']))
  20.           {
  21.                   //$myfile="E:\sachins\projects\me\myfile.txt"; -This is static path
  22.                       $myfile= $_FILE["fr"];   //i want value of fr which is input file type
  23.                 echo $myfile;
  24.           $fr=fopen($myfile,"r");
  25.                       while (!feof($fr))
  26.         {                
  27.         echo  fgets($fr). "<br />";
  28.         }
  29.           ?>
  30.      </body>
  31. </html>
  32.  
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...
May 22 '07 #1
Share this Question
Share on Google+
1 Reply


Atli
Expert 5K+
P: 5,058
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:
Expand|Select|Wrap|Line Numbers
  1. <?php ?>
  2. <form enctype="multipart/form-data"  action="?" method="POST">
  3.   <input type="file" name="fr" id="fr"> <br><br>
  4.   <input type="submit" name="submit" value="Read" >
  5. </form>
  6.  
  7. <?php
  8.   if(isset($_POST['submit']))
  9.   {
  10.     echo "<pre>";
  11.     print_r($_FILES);
  12.     echo "</pre>";
  13.   }
  14. ?>
  15.  
May 22 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.