-3

When I click on a link, I can't download the image, only visualize it. What is my mistake?

PHP:

  require('conecta.php');
  ini_set('display_errors',1); error_reporting(E_ALL);  
    $cSQL="SELECT ID_PIC, PIC, NOMBRE FROM FOTOS";
    $stmt=$oConni->prepare($cSQL) or die($oConni->error);
    $stmt->execute(); 
    $stmt->store_result();
    $stmt->bind_result($id, $pic, $nombre);
    //$i=0;
    echo '<table cellspacing="0">';
    while ($stmt->fetch()) {

        if (!empty($pic)){ 
            echo'<tr><td><img class="sifoto" src="images.php? id='.$id.'" width="100" height="100"  /></td></tr>';
        }
        echo'<tr><td value='.$id.'><a href='.$nombre.'>DOWNLOAD</a></td></tr>'; 
        //$i++;
    }   
    $stmt->close();
    echo'</table>';

 ?>
halfer
  • 19,824
  • 17
  • 99
  • 186
jal
  • 533
  • 1
  • 5
  • 13

2 Answers2

2

Thgis question is similar to another. Please check here - Force file download with php using header()

You need to set the headers for a file transfer.

Community
  • 1
  • 1
KPheasey
  • 1,765
  • 16
  • 22
  • Make sure to set that header in the php file serving the image, not the one linking to it (which is what was pasted) – MrGlass Apr 10 '13 at 19:57
0

As @WesleySchleumer said, you need to add quotes to the download link. change:

echo'<tr><td value='.$id.'>DOWNLOAD<a href='.$nombre.'></a></td></tr>';

to:

echo'<tr><td value='.$id.'><a href="'.$nombre.'">DOWNLOAD</a></td></tr>';

MrGlass
  • 9,094
  • 17
  • 64
  • 89