2

This is jquery part

<script>
    function copy()
    {
        try
        {
            $('#link').select();
            document.execCommand('copy');
        }
        catch(e)
        {
            alert(e);
        }
    }
</script>

This HTML part

<div class="row">
       <?php
        //scan "uploads" folder and display them accordingly
       $folder = "uploads";
       $results = scandir('uploads');

       foreach ($results as $result) {
        if ($result === '.' or $result === '..') continue;          

        if (substr($result, -4) == '.jpg' or substr($result, -4) == '.png') {
            echo '
            <div class="col-md-3">
                <div class="thumbnail">
                    <img src="'.$folder . '/' . $result.'" alt="...">
                        <div class="caption">
                        <p>'. $result .' </p>
                        <p><a href="'.$folder . '/' . $result.'" role="button">Download</a> 
                        <a href="remove.php?name='.$result.'" role="button">Remove</a> </p>
                       <textarea id="link" style="display:none">'.$folder . '/' . $result.'</textarea>
                     <div align="center"><span class="btn-md" onclick="copy();">copy</span></div>
                    </div>
                </div>
            </div>';
                }                        
       }
       ?>
    </div>

I want to make the button copy the file URL to the user clipboard automatically when clicked. But when it's loping and click on the copy button in every link copy the first one only? But I want to copy the link for every individual.

Please help me by suggesting what I should try to make it work.

Saif Morshed
  • 51
  • 1
  • 9
  • And, you asked exactly same question http://stackoverflow.com/questions/35281792/copy-text-to-clipboard-on-button-click-into-a-foreach-lope 18 Hours Ago. – Nana Partykar Feb 09 '16 at 18:37
  • I read this article But it only copy the first one! I want to copy every individual link. Pls suggest for that – Saif Morshed Feb 09 '16 at 18:38

0 Answers0