I want to let user select a file. The path location should be stored in a JavaScript string. later after validating i want to make a ajax call to server to upload the file on to the server using PHP.
I don't want to submit form directly as page would reload and there are many sql queries executed and would be unnecessary load on server.
<input type="file" id="files" name="files[]" multiple />
<output id="list"></output>
<script>
function handleFileSelect(evt) {
var files = evt.target.files; // FileList object
// files is a FileList of File objects. List some properties.
var output = [];
for (var i = 0, f; f = files[i]; i++) {
alert(JSON.stringify(f));
output.push('<li><strong>', escape(f.name), '</strong> (', f.type || 'n/a', ') - ',
f.size, ' bytes, last modified: ',
f.lastModifiedDate ? f.lastModifiedDate.toLocaleDateString() : 'n/a',
'</li>');
}
document.getElementById('list').innerHTML = '<ul>' + output.join('') + '</ul>';
}
document.getElementById('files').addEventListener('change', handleFileSelect, false);
</script>
This alert gives me details but not the path that i want.
Any help on getting the path so i can just pass the string via ajax using jquery and upload file with php using move_uploaded_file.
Thanks in advance.