0

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="&lt;a href=&quot;&quot    id=&quot;lnk&quot   &gt;&lt;/a&gt;  " />
<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;

};
};
Abe.S
  • 21
  • 7
  • It should be possible to upload files with dots in the name, otherwise almost no files would be uploadable. What exactly is the problem this is giving you? We need a bit more detail than just "it's not letting me". – ADyson Nov 24 '17 at 11:52
  • @ADyson it seems to me that i can't do both submitting it to my up.php and google forms. its either one of them. while what i am looking for is to uplode it first to my server in order to send the URL to google forms. The must be the same name and for it to send correctly to both form actions at the same time i need a bypass... – Abe.S Nov 24 '17 at 11:59
  • It's not 100% clear really - what exactly do you want to upload to google? The actual image? Or just a URL to the image as it exists on your server (following your upload)? – ADyson Nov 24 '17 at 12:19
  • Just the URL to the image as it exists on my server following my upload. – Abe.S Nov 24 '17 at 12:21
  • ok so I think you can do it as two forms (this doesn't necessarily need to be visible to the user, forms are not visible markup). One containing the "file" input. User selects a file and clicks ok. This is uploaded to your server using ajax. The server responds back with the URL of the newly uploaded file.You use Javascript to put this value into a text field on your second form (the one which points to google) which has the correct "name" attribute as required by google, and upload. What you seem to be doing now is trying to use one field for two different things (ie a file, and a URL string) – ADyson Nov 24 '17 at 12:27
  • I see no reason why you would need to do that, and also it's impossible to put a string into a "file" input so I can't see it would ever work. Your server can accept input using whatever name you like, there's no reason I can think of for it to have to use the same values the google form does. – ADyson Nov 24 '17 at 12:31
  • That will be exactly what i would be looking for. Would u be so kind and show me some examples i can work with? – Abe.S Nov 24 '17 at 12:32
  • well your file uploading already looks basically ok I think, you just need to move it into a different form. That should be fairly obvious how to do? Change your ` – ADyson Nov 24 '17 at 12:43
  • @Adyson Ok working on it right now. I got it to upload and successfully sent a short link of the file name to google. (, abc.jpg,) How would i go about to get the full path of URL (http://mywebstie.com/abc.jpg) and remove the commas? – Abe.S Nov 24 '17 at 13:11
  • since I don't know how you're producing that string it's kinda hard to tell you exactly how to fix it. If you share your code it might be easier. Have you traced at which point in the process the commas seem to be getting introduced? – ADyson Nov 24 '17 at 14:25
  • I got rid of the commas it happened due to having multiple inputs with same ID (Due to testing) i got rid of it once i cleaned the code. i will be working on getting a full link otherwise i will be update with code in a fue hours. Either way success or not i will keep u updated. – Abe.S Nov 24 '17 at 21:14
  • @ADyson Maybe something like this will work? https://stackoverflow.com/questions/8169027/how-can-i-submit-a-post-form-using-the-a-href-tag#22076149 – Abe.S Nov 25 '17 at 03:42
  • if you need the submit button to look like a link, then yeah. Otherwise a normal submit button would be fine. Note that's not the same thing as the URL you need to add to your second form (the one which will be sent to google) -that needs to be a paramter which is inside a textbox. – ADyson Nov 25 '17 at 08:17
  • I found a way. may not be the best way. but it really did help. i will post it as my answer. – Abe.S Nov 26 '17 at 23:39

0 Answers0