|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Getting the remote file path from <input type="file">
I'm using a form to upload a file to save in a mySQL database, however I need to store the original file path on the clients (the user uploading the file) computer.
The file path is shown in the field that selects the file, I just need to post it or save it in a session somehow. Any thoughts? Thanks Steve. |
|
#2
|
|||
|
|||
|
$HTTP_POST_FILES[’userfile’][’name’] - should contain the original file name of the file being uploaded so you should be able to simply assign that to a session var or a cookie or where you intend to save it.
<input type="file" name="myfile "> session_start(); session_register("userfile"); $userfile = $HTTP_POST_FILES[’myfile ’][’name’]; Alan |
|
#3
|
|||
|
|||
|
Thanks for the tip Alan
That will get me the name of the file being passed, but what I need is the entire path that the file held when it was uploaded. ex 'C:/WINDOWS/temp/something.txt' I want to add the 'C:/WINDOWS/temp/' to a session variable or at least have it posted to the next page. I need to store the path in order to restore that file to the right location. |
|
#4
|
|||
|
|||
|
I very much doubt this is possible, it wouldn't be good for a browser to reveal information about a users file system.
|
|
#5
|
|||
|
|||
|
$HTTP_POST_FILES[’myfile ’][’name’] will actually contain the "entire" file name including the path.
Alan |
|
#6
|
|||
|
|||
|
uh, no it won't
|
|
#7
|
|||
|
|||
|
When I use either $HTTP_POST_FILES['filename']['name'] or $_FILES['filename']['name'] I only get the name of the file and not the path.
I'm using PHP version 4.3.0 with registered_globals = off; Here's my code : This is the form that inputs the file <form method="POST" action="upload.php" ENCTYPE="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="1000000"> <input type="hidden" name="action" value="upload"> <table border="1"> <tr> <td>File: </td> <td><input type="file" name="binFile" default="none"></td> </tr> <tr> <td colspan="2"><input type="submit" value="Upload"></td> </tr> </table> </form> It POSTs to a file with this code. print_r($HTTP_POST_FILES); print $HTTP_POST_FILES['binFile']['name']; If I enter a file called thefile.txt Array ( [binFile] => Array ( [name] => thefile.txt [type] => text/plain [tmp_name] => D:\Program Files\PHP\uploadtemp\php3D8.tmp [error] => 0 [size] => 41 ) ) Stuff in the file only the path of the temp file on the server is listed |
|
#8
|
|||
|
|||
|
My appologies... I assumed after seeing:
"The original name or path of the file on the sender’s system ." in the PHP manual when describing the use of $HTTP_POST_FILES[’userfile’][’name’] that "name or path" implied that if a path was used, a path would be present in the resulting var. Alan |
|
#9
|
|||
|
|||
|
Alright, thanks very much Alan.
I'll have to look for another way around this. Steve |
|
#10
|
|||
|
|||
|
a thought, it may or may not work...
in your form add a hidden field for the remote file path, and update it when the file control changes. Code:
<form name="myform"> <input type="hidden" name="remote_file_path" value=""> <input type="file" name="upfile" onchange="document.myform.remote_file_path.value=this.value;"> |
|
#11
|
|||
|
|||
|
this seems to work:
Code:
<?php echo $_REQUEST['remote_file_path']; ?> <br> <form name="myform"> <input type="hidden" name="remote_file_path" value=""> <input type="file" name="upfile" onchange=""> <input type="button" value="submit" onclick="document.myform.remote_file_path.value=document.myform.upfile.value;document.myform.submit();"> </form> |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > PHP Development > Getting the remote file path from <input type="file"> |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|