I have a simple form that uses a bit of jquery,
<form action="" method="post"
enctype="multipart/form-data">
<label for="file">Upload File:</label>
<input type="file" name="userfile" id="userfile" />
<input type="button" value="Submit" onclick="uploadfile()"/>
</form>
the uploadfile() in my .js file looks like this:
function uploadfile(){
var userfile = document.getElementById('userfile').value;
var username = document.getElementById('username').value;
$.post("php/upload.php", {userfile: userfile,username: username},function(data) {
$('#headercontent2').show().html (data);
});
}
as you can see it is supposed to post userfile to the php script see below:
<?php
$userfile = $_POST['userfile'];
$uploaddir = '../data/daviesjc/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
echo "<p>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Upload failed";
}
?>
It doesnt like this and I dont know how I can post the file back to php upload script? it works if I dont use jquery, but I need to for this simple project.. can anyone help please?
Thanks