So I've managed the image preview where users can now select a file and preview it before uploading:
makeapost.php
<input type="text" id="thetitle" name="title" placeholder="Title">
<input type="text" id="imagepath" name="imagepath" hidden>
<input type="file" name="file" onchange="readURL(this)">
<img src="" id="img"> <br>
<video width="320" height="240" style="display:none" controls autoplay>
<source src="" id="forvideo">
</video>
main.js
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
document.querySelector("#img").setAttribute("src",e.target.result);
};
reader.readAsDataURL(input.files[0]);
}
}
However, clearly it doesnt work with videos and I would like to know how I could preview both images and videos from one input, without having to seperate them both. Any tips? Thanks!