I have written a php script for uploading images. I want to use this script in my all pages. The problem is that the name of input file <input type="file" name="input_name">
in the server side. I am using a different input name so I do not know how I detect the input name in the server side?
Html code :
<input type="file" name="my_input_name" id="inptId">
JS Code:
var fd = new FormData();
var image = document.getElementById("inptId");
fd.append("my_input_name",image);
$.ajax({
method:post,
url:uniq_file_uploader.php,
....,
....,
data:fd,
sucess:function(e){....}
});
EG: my php code:
<?php
if($_SERVER["REQUEST_METHOD"] === "post"){
if(!empty($_FILES['Constant_Name']['name'][0])){//check also for multiple uploads
// constant_name is name of input file (eg. my_input_name)
// but problem is input name is not always same..
// on every page it is different name
}else {return "NO file selected";}
if(!empty($_FILES['Constant_Name']['name'])){
//it is for one file upload detect
//this is for one file upload beacuse this is for using upload his avatar. can't be a lot of avatar
}else{return "no file selected";}
}else {return "request is not post"}
?>