I've got a upload script that uses PHP (for upload), and jQuery for the progress bar. Here's the issue. I want it to only be allowed to have MP4s uploaded. It's working, I just need help to figure out how to fix the errors. See, if it isn't a mp4 it is supposed to echo Only MP4s are allowed at the time.
elsewise, it will move the uploaded file to the users folder, then echo Done. Want to see it on <a href=channelname>your channel?</a>
. Here's the issue. It won't echo out the errors. It just says "Done." whenever the file is done uploading. I would greatly appreciate help on how I can fix this.
Here's my code.
if ($_SERVER["REQUEST_METHOD"] == "POST" && !empty($_FILES["userfile"])) {
$file_type = $_FILES['userfile']['type']; //returns the mimetype
$allowed = array("video/mp4");
if(!in_array($file_type, $allowed)) {
echo "Only MP4 videos are allowed to be uploaded because of security, and this is still a beta.";
echo "<button onclick='window.location.reload()'>Upload a different file</button>";
echo "<script>removeDummy()</script>";
} else {
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
move_uploaded_file($_FILES['userfile']['tmp_name'],"videos/".$user."/".$_FILES['userfile']['name']);
echo "Done. Want to see it on <a href='channelname'>your channel</a>?";
}
}
and here's the jQuery and JS
function toggleBarVisibility() {
var e = document.getElementById("bar_blank");
e.style.display = (e.style.display == "block") ? "none" : "block";
}
function createRequestObject() {
var http;
if (navigator.appName == "Microsoft Internet Explorer") {
http = new ActiveXObject("Microsoft.XMLHTTP");
}
else {
http = new XMLHttpRequest();
}
return http;
}
function sendRequest() {
var http = createRequestObject();
http.open("GET", "progress.php");
http.onreadystatechange = function () { handleResponse(http); };
http.send(null);
}
function handleResponse(http) {
var response;
if (http.readyState == 4) {
response = http.responseText;
document.getElementById("bar_color").style.width = response + "%";
document.getElementById("status").innerHTML = response + "%";
if (response < 100) {
setTimeout("sendRequest()", 1000);
}
else {
toggleBarVisibility();
document.getElementById("status").innerHTML = "Done.";
}
}
}
function startUpload() {
toggleBarVisibility();
setTimeout("sendRequest()", 1000);
}
(function () {
document.getElementById("myForm").onsubmit = startUpload;
})();
When it gets done, it says "Done." like in the jQuery. I want it to echo like the PHP does, not from the jQuery.