开发者

Choose a local file w/o uploading the chosen file

I am making a simple development tool for myself using PHP on my local development server.

I would like a way to have a simple file-chooser to select a file without uploading it, but just retaining the file path. This is useful, because I will be the only one using the tool, and so PHP will have access to the chosen file without having it uploaded.

My fi开发者_如何转开发rst thought is to have a <input type="file"...>, but as far as I know, there's no way to prevent the upload from happening.

Is there a way to do this?


Assuming this will only ever be run locally, you could write a PHP-based file chooser/locator. You would have complete control over behavior and presentation this way.


Ill do something like the same input type file.

The form will not be a multipart one, a normal form with a onSubmit event, that take the value of the file input and will assign that value to a hidden input that is taken in the action of that form...


Though you can get the file name of a file entered in an <input type="file" …> field using JavaScript (and send this name to the server, e.g. using XMLHttpRequest), you can't get the full path, as this would create a huge security implication.

Example (you don't have to use a <form> for this):

<input type="file" id="fileField">
<input type="button" value="Click here!" onclick="getFileName()">

<script>
function getFileName() {
  var fileEl = document.getElementById("fileField");
  console.log(fileEl.value);
  // other stuff, e.g. send fileEl.value using XMLHttpRequest
}
</script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜