pickzy.com

C  |  C++  |  Objective-C  |  VC++  |  Win32  |  MFC  |  Java  |  Php  |  Delphi  |  Visual Basic  |  .Net  |  Networking  |  General  |  Games  |  Jobs  |  Javascript  |  




Menu

pickSourcecode.com


        

 




 

Php > Solution

 

php - input tag, type file, need the full path

Question:
I need to be able to pass the full path name of a file that the user
selects via the browse button in html.  IE passes this path as part of the post, 
Firefox only gives me the filename.  
Irregardless of browser I need the whole path.  

** I don't need the text part of the file input to default to a specific value, 
Just the path once the user selects any file at all.
?

<?php
        $tempStr = $_POST['getPath'];
        $count   = 0;
        $len   = strlen($tempStr);
        
if($len > 0)
{
        while($count < $len)
        {
              $temp  = substr($tempStr, $count, 1);
    
if ($temp == "\\")                  
                {
      $count++;
       $temp  = substr($tempStr, $count, 1);
    
if ($temp == "\\") {
            $path = $path."/";
     } 
     }else
          $path = $path.$temp;
           $count++;
         }
     echo $path;
        }
?> 

<!DOCTYPE HTML PUBLIC "-
//W3C//DTD  HTML  4.01  Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd">
<HTML>

<HEAD>

<TITLE>File Uploading Interface</TITLE>

<script language="JavaScript" type="text/javascript">

<!--

function getDirPath() {

   document.getElementById('inputText').value = document.getElementById('myfile').value;  

}

//-->
</script>

</HEAD>

<BODY>

<CENTER>

<BR><BR>

<FORM enctype="multipart/
form-data" NAME=MyForm ACTION="submit.php" METHOD="POST">
  <INPUT TYPE="hidden" NAME="command" VALUE="1">

  <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="100000">

  <INPUT TYPE="hidden" name="getPath" id="inputText">

  <TABLE>

  <TR>

  <TD>Choose File</TD>

  <TD><INPUT NAME="MyFile" TYPE="File" id="myfile" onclick="javascript:getDirPath();"></TD>

  </TR>

  <TR>

  <TD COLSPAN="2"><INPUT NAME="submit" VALUE="Path" TYPE="submit"></TD>

  </TR>

  </TABLE>

</FORM>

</CENTER>

</BODY>

</HTML>



 
Privacy Policy | About Us