I have this html
page with ajax
function called upload(name)
to send a data to a PHP
file (upload-ad-image-inc.php) for a image upload process.
I have already tried passing data using ajax
to the relevant PHP
file (upload-ad-image-inc.php).
And I got the passed data using a POST
and assign it to a variable and so far so good. Data is passed but it is kind of missing after that.
This is my Ajax function:
function upload(name) {
$(document).ready(function () {
$.ajax({
url: 'includes/upload-ad-image-inc.php',
type: 'POST',
dataType: "json",
success: function (data) {
alert(data);
},
data: {
file: name
}
}).done(function (data) {
alert(JSON.stringify(data));
});
});
}
this is my upload-ad-image-inc.php
$ind = filter_input(INPUT_POST, 'file');
echo $ind; //it shows file name successfully
$adId = $_SESSION['adid'];
$userId = $_SESSION['userid'];
//after this the value of $ind is missing, cannot apply to any of above.
//They show empty outputs
$file = $_FILES[$ind];
$fileName = $_FILES[$ind]['name'];
$fileTempName = $_FILES[$ind]['tmp_name'];
$fileSize = $_FILES[$ind]['size'];
$fileError = $_FILES[$ind]['error'];
$fileType = $_FILES[$ind]['type'];
echo $fileName; //this is where my problem. It doesn't show file name
In this part I get the file name
attributes value
$ind = filter_input(INPUT_POST, 'file');
echo $ind; //it shows file name successfully
but in below i don't get anything but empty
values
$file = $_FILES[$ind];
$fileName = $_FILES[$ind]['name'];
$fileTempName = $_FILES[$ind]['tmp_name'];
$fileSize = $_FILES[$ind]['size'];
$fileError = $_FILES[$ind]['error'];
$fileType = $_FILES[$ind]['type'];
echo $fileName; //this is where my problem. It doesn't show file name
This is my `HTML'
<div class="image-uplod">
<label class="custom-file image-uplod">
<input style="display: none;" type="file" accept="image/*" onchange="readURL(this, 'blah1', 'file1');" id="file1" name="file1" class=" btn btn-primary">
<button style="display: none;" type="submit" name="submitUpload" class="custom-file-control btn btn-primary"><i class = 'fa fa-save'></i> Save</button>
</label>
<label class="custom-file image-uplod">
<input style="display: none;" type="file" accept="image/*" onchange="readURL(this, 'blah2', 'file2');" id="file2" name="file2" class=" btn btn-primary">
<button style="display: none;" type="submit" name="submitUpload" class="custom-file-control btn btn-primary"><i class = 'fa fa-save'></i> Save</button>
</label>
<label class="custom-file image-uplod">
<input style="display: none;" type="file" accept="image/*" onchange="readURL(this, 'blah3', 'file3');" id="file3" name="file3" class=" btn btn-primary">
<button style="display: none;" type="submit" name="submitUpload" class="custom-file-control btn btn-primary"><i class = 'fa fa-save'></i> Save</button>
</label>
<label class="custom-file image-uplod">
<input style="display: none;" type="file" accept="image/*" onchange="readURL(this, 'blah4', 'file4');" id="file4" name="file4" class=" btn btn-primary">
<button style="display: none;" type="submit" name="submitUpload" class="custom-file-control btn btn-primary"><i class = 'fa fa-save'></i> Save</button>
</label>
</div>