I want to get the exact local path of input file in my php code but no success here is the code <input type="file" name="img"> <?=$_FILES[name]?> the above will only display the file name not the exact local path. For exampel the exact local path of the file is C:\tmp\img1.jpg it only show img1.jpg I need to get the exact path. I tried also the following <input type="hidden" name="tmppat" value=''> <input type='file' name='img' onchange ="tmppat.value=this.value"> still it shows the file name only...
Generally uploaded files are in temporary directory. If you wish to specifically have the file in any other directory, then use move_uploaded_file() function.
As uploaded files go into temp folder of the system on server, you can simply concatenate the path as prefix: $full_path = sys_get_temp_dir().$_FILES['img']['tmp_name']; Code (markup): function sys_get_temp_dir() returns you the temp folder path. Secondly, temp folder of the system is defined in environment variable paths, so accessing file directly using $_FILES['img']['tmp_name'] will allow you to read same file. I hope it helps.
I am not sure what you want exactly. But I suggest that you do a: <?php var_dump($_FILES); ?> PHP: This gives you all the information available in the $_FILES collection. Do understand that if you are expecting that PHP will tell you that the original path of the file was "c:\documents and settings\whatever\desktop\some document.doc" -- no, it won't. Browser security/privacy issue.
Well, I misunderstood your question first. In Internet Explorer 8 using jQuery it WORKS perfect, and returns path too. If it is working using jQuery, ofcourse it works with plain javascript as well. So for reference it is here. While your user selects the file, you can save path in hidden variable and forward to next POST data receiving script. NOTE : This doesn't work in Firefox, I am not sure about other browser. Quick Example for IE8: <script src="jquery-1.3.2.min.js"></script> <input type="file" name="file1" id="file1" /> <input type="button" value="Check" /> <div id="out"></div> <script> $(function() { $("#file1").change(function(e) { var arr = $(this).val().split("\\"); delete arr[arr.length-1]; arr = arr.join("\\"); $("#out").html(arr); }); }); </script> Code (markup):