I am running a function and it returns download link, I'm looking forward to pass this as variable to php in same page to send notifcation with image attached in it. But I try cookies method and rest other methods suggested by many but none of them works.
After Upload is finished I store it in variable like
var ImageLink = downlaodURL;
and I want to accesss in php in
$notification->setImage("Here I want to get variable");
Here is my Full Code
<div class="container" style="margin-top: 30px;">
<div class="row">
<div class="col-lg-6">
<form action="" method="post" onchange="myFunction()">
<div class="form-group">
<label for="title">Title:</label>
<p class="lead emoji-picker-container">
<input value="" type="text" required="" class="form-control" id="title" placeholder="Enter Notification Title" name="title">
</p>
</div>
<div class="form-group">
<label for="message">Message:</label>
<p class="lead emoji-picker-container">
<textarea required="" class="form-control" rows="5" id="message" placeholder="Enter Notification Message" name="message"> </textarea>
</p>
</div>
<div class="form-group"id="image_url_group">
<label for="image_url">Image URL:</label>
<input type="file" class="form-control" id="image_url" placeholder="Enter Image URL" name="image_url" accept=".xlsx,.xls,image/*,.doc, .docx,.ppt, .pptx,.txt,.pdf" >
</div>
<button type="submit" class="btn btn-info">Submit</button>
</form>
</div>
<div class="col-lg-6">
</div>
</div>
</div>
</body>
<script type="text/javascript">
var config = {
apiKey: "My Key",
authDomain: "",
databaseURL: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: "",
measurementId: ""
};
firebase.initializeApp(config);
function myFunction(){
var messagesRef = firebase.database().ref('Notification');
//firebase storage reference
//it is the path where yyour image will store
var storageRef=firebase.storage().ref('Notification/'+imageName);
//upload image to selected storage reference
var uploadTask=storageRef.put(image);
uploadTask.on('state_changed',function (snapshot) {
//observe state change events such as progress , pause ,resume
//get task progress by including the number of bytes uploaded and total
//number of bytes
var progress=((snapshot.bytesTransferred/snapshot.totalBytes)*100).toFixed(0);
console.log("upload is " + progress +" done");
},function (error) {
//handle error here
console.log(error.message);
},function () {
//handle successful uploads on complete
uploadTask.snapshot.ref.getDownloadURL().then(function (downlaodURL) {
// I want To Pass this variable to PHP in Image_url
var ImageLink = downlaodURL;
});
});
}
</script>
<?php
if(isset($_POST['title'])){
require_once __DIR__ . '/notification.php';
$notification = new Notification();
$title = $_POST['title'];
$message = isset($_POST['message'])?$_POST['message']:'';
$imageUrl = isset($_POST['image_url'])?$_POST['image_url']:'';
$notification->setTitle($title);
$notification->setMessage($message);
$notification->setImage("Here I want to get Download URL");
$firebase_api = $_POST['firebase_api'];
$topic = $_POST['topic'];
$requestData = $notification->getNotificatin();
}
?>
Thanks in advance.

