Я использую react с php. Как правильно загрузить картинку?
Пробую так(получаю File is not an image.):
php:
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
javascript:
constructor(props) {
super(props)
$(document).ready(function (e){
console.log(1)
$("#uploadForm").on('submit',(function(e){
console.log(2)
e.preventDefault();
$.ajax({
url: "https://worldwideshop.ru/vbot-dev/api/?command=upload_img&file_name=1.jpeg",
type: "POST",
data: new FormData(this),
contentType: false,
cache: false,
processData:false,
success: function(data){
// $("#targetLayer").html(data);
console.log(data)
},
error: function(){
console.log(4)
}
});
}));
});
}
html:
<form id="uploadForm" method="post">
<label>Upload Image File:</label><br/>
<input name="userImage" type="file" class="inputFile" />
<input type="submit" value="Submit" class="btnSubmit" />
</form>