-
Notifications
You must be signed in to change notification settings - Fork 21
/
uploadfile.html
50 lines (46 loc) · 1.7 KB
/
uploadfile.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<html>
<body>
<form action="" method="post" enctype="multipart/form-data" onsubmit="AJAXSubmit(this); return false;">
<fieldset>
<label >Select photo of expense:
<input type="file" name="file"></label>
<input type="submit" value="Submit" id="submit"/>
<img id="uploaded">
<div id="results"></div>
</fieldset>
</form>
<style>
#submit{
background-color: blue;
margin-top:9px;
}
</style>
<?php
$cloud_name = "asnas";
$api_key = "225422951542744";
$api_secret = "xT8vKGkiuchegOzxUKNNVgni1W8";
$timestamp = time();
$signature = sha1("timestamp=".$timestamp.$api_secret);
?>
<script>
window.ajaxSuccess = function () {
response = JSON.parse(this.responseText);
console.log("ajaxSuccess", typeof this.responseText);
document.getElementById('uploaded').setAttribute("src", response["secure_url"]);
document.getElementById('results').innerText = this.responseText;
}
window.AJAXSubmit = function (formElement) {
console.log("starting AJAXSubmit");
var xhr = new XMLHttpRequest();
xhr.onload = ajaxSuccess;
var formData = new FormData(formElement);
formData.append("timestamp", '<? php echo $timestamp ?>');
formData.append("signature", "<?php echo $signature ?>");
formData.append("api_key", '<?php echo $api_key ?>');
console.log(formData);
xhr.open("post", "https://api.cloudinary.com/v1_1/<?php echo $cloud_name ?>/image/upload");
xhr.send(formData);
}
</script>
</body>
</html>