0

This is jquery part I created

<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 one copy the first one? But I want to copy the link for each but each on his link.

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

Saif Morshed
  • 51
  • 1
  • 9

0 Answers0