UPDATE: SOLVED! (Answer below) I am trying to add vars with an image file I am uploading. I am able to upload the image fine but I can't seem to send the wanted vars to php and send them back etc.
I am hoping to send at least this var called $Destination to php, along with image data, which is working, and maybe other vars too. Below is the line I am trying to send.
var Dest = '<? echo $Destination;?>';
Here is my script:
function myFunction() {
var = Dest: '<? echo $Destination;?>'; // This one
var file_data = $('#ImageuploadBtn').prop('files')[0];
var form_data = new FormData();
form_data.append('file', file_data);
$.ajax({
url: 'admin/myUpload.php',
dataType: 'text',
cache: false,
contentType: false,
processData: false,
data: form_data,
type: 'POST',
success: function(php_script_response)
{
console.log(php_script_response);
var html = '<img src="../files/' + php_script_response + '" class="DisplayMainImage img-responsive">';
$( ".MainImage" ).replaceWith(html);
}
});
My PHP:
<?php
if ( 0 < $_FILES['file']['error'] ) {
echo 'Error: ' . $_FILES['file']['error'] . '<br>';
}
else {
move_uploaded_file($_FILES['file']['tmp_name'], '../files/' . $_FILES['file']['name']);
$Message = $_FILES['file']['name'];
//// $Destination DOES NOT WORK
$Destination = $_POST['Dest']; /// NO WORK
echo $Message;
}
?>
SOLVED ISSUE: I needed these lines.
var Dest = '<? echo $Destination;?>';
form_data.append('Dest', Dest);
form_data.append('Dest', Dest);to add the data?