I am basing my answer off this answer. Not sure where you got inputvalue
from, but replace it with data
.
function processIt(id, flag, inputvalue)
{
var data = new FormData();
data.append('imagefile', inputvalue);
data.append('id', id);
data.append('flag', flag);
$.ajax({
url: 'modify.php',
type: 'POST',
data: data,
contentType: false,
processData: false,
cache: false,
success: function (msg) {
alert(msg);
}
});
}
And just a friendly code review in your PHP code, avoid using $_REQUEST
and you are doing too much unnecessary checking in your IF condition. Here's one way to fix it:
if (!empty($_POST['flag']) && !empty($_POST['id'])) {
$flag = $_POST['flag'];
$id = $_POST['id'];
echo "Processed";
} else {
echo "Request not processed";
}
You may also try filter_input function which offers some validation and sanitization features. Unfortunately, there is no INPUT_FILE and you have to use $_FILES
array.
Assuming id is an integer, you could do something like:
$flag = filter_input(INPUT_POST, 'flag', FILTER_SANITIZE_STRING);
$id = filter_input(INPUT_POST, 'id', FILTER_VALIDATE_INT);
if ($flag && $id) {
echo "Processed";
} else {
echo "Request not processed";
}