I am unable to successfully upload an image/file to my server. The php is as follows:
//This is the directory where images will be saved
$uploadDir = "./";
$uploadFile = $uploadDir . basename( $_FILES['photo']['name']);
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $uploadFile)){
echo "The file has been uploaded successfully.";
} else {
print_r($_FILES);
}
I chose the directory at which this script lives, to ensure the functionality before I upload to the final directory. I want to upload photo's, and will check for file extensions later - but for now I at least need the upload functionality to work.
I get an empty array returned.
** EDIT **
Also, enctype="multipart/form-data"
is enabled on the form, and I am submitting it via AJAX.
The form is as follows:
<form id="imageUploadForm" name="imageForm" enctype="multipart/form-data">
<label for="photo" class="blogLabel">Upload an Image</label>
<input type="file" name="photo" id="imageUpload" onChange="uploadImage();">
</form>
I do realize that I shouldn't use "onChange" to submit the form.
The AJAX to submit the form is as follows:
function uploadImage() {
$.ajax({
type:'POST',
url:'imageController.php',
data:$('#imageUploadForm').serialize(),
success: function(responseSubmit) {
alert(responseSubmit);
}
});
};