Reputation: 27436
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 first 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?
Upvotes: 1
Views: 2440
Reputation: 4621
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.
Upvotes: 2
Reputation: 21763
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>
Upvotes: 1
Reputation: 8169
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...
Upvotes: 1