I have googled for 6 hours and I found some methods to bypass some of the trouble I had. What I am trying to do is >upload img> get the URL to img> upload URL into google forms> now I constantly running into issues for example the ID google provides has a dot in the input name. Second thing I don't know how I will do after uploading img to get the full URL. Now I did manage to find a way to auto uplode the img. Hopfully that can help out with the code.
The Silent Uploder `
<script>
$(document).ready(function() {
$('#entry.1234567').change(function(){
var file_data = $('#entry.1234567').prop('files')[0];
var form_data = new FormData();
form_data.append('file', file_data);
$.ajax({
url: "up.php",
type: "POST",
data: form_data,
contentType: false,
cache: false,
processData:false,
success: function(data){
console.log(data);
}
});
});
});</script>
Getting Info
<script>
var oFReader = new FileReader();
oFReader.readAsDataURL(document.getElementById("entry.1609778345").files[0]);
oFReader.onload = function (oFREvent) {
document.getElementById("imgTampil").src = oFREvent.target.result;
};
</script>
'
Html Code
<form action="https://docs.google.com/forms/d/e/1FAIpQ__________z/formResponse" target="_self" method="POST" id="mG61Hd">
<input type="file" name="entry.1234567" id="entry.1234567" onchange="displ_img();" aria-label="LOGO " aria-describedby="i.desc.710104157 i.err.710104157" value="" dir="auto" data-initial-value=""/>
'
Shows A view of img
<script>
function displ_img() {
//to display the image
var oFReader = new FileReader();
oFReader.readAsDataURL(document.getElementById("entry.1234567").files[0]);
oFReader.onload = function (oFREvent) {
document.getElementById("imgTampil").src = oFREvent.target.result;
};
};
</script>
up.php
$src = $_FILES['file']['tmp_name'];
$targ = "uploads/".$_FILES['file']['name'];
move_uploaded_file($src, $targ);
Now seeing above I know that the Input Name is not letting me pass post as I have a Dot in the name. How would I avoid it? and also how would I import a full link as a results instead of 123.jpg to http://www.sample.com/123.jpg
Update
I got the img to upload (on my server)> and the link is being sent to the google form > I got the link to work as well. How would i go about importing the a href in a input?
Here is the code
HTML
<input type="file" onchange="displ_img();" id="fileToUpload" Value="jkhsd">
<img align="right" id="imgTampil" alt="" src="" class="img-responsive"/>
<a href="" id=lnk ></a> <br>
I tried this.
<input name="entry.1609778345" type="text" value="<a href="" id="lnk" ></a> " />
<input type="text" id="lnk" alt="" src="" />
end script
function displ_img() {
var oFReader = new FileReader();
// Copy url link and replace.
var userInput = document.getElementById('fileToUpload').value;
var filename = userInput.replace(/^.*[\\\/]/, '')
var lnk = document.getElementById('lnk');
//to display the image
oFReader.readAsDataURL(document.getElementById("fileToUpload").files[0]);
oFReader.onload = function (oFREvent) {
document.getElementById("imgTampil").src = oFREvent.target.result;
lnk.href = "" + lnk + filename;
lnk.innerHTML = lnk.href;
};
};