By using a force download script. The link attached to the image will be your force download script. You can find one here: http://elouai.com/force-download.php
Those are both great scripts, but is it possible to make it so that the file is on another server? For instance; User clicks on a download link on site A, but the image is on site B. Note: I did set the filepaths to the location of the image, but no results.
The reason that didn't work was because, file_exists only works on locally hosted files and not remote (too my knowledge). Theifore use this... <?php $file = 'http://forums.digitalpoint.com/images/misc/dps_logo.gif'; header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($file)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); ob_clean(); flush(); readfile($file); exit; ?> PHP:
Is the content type not already defined? case "gif": $ctype="image/gif"; break; case "png": $ctype="image/png"; break; case "jpeg": case "jpg": $ctype="image/jpg"; break; PHP:
Yes, but you didn't mention that earlier. Follow this example -> http://forums.digitalpoint.com/showpost.php?p=13461746&postcount=5
Oh, your the one who showed me that script lol. But the example seems to be working, except you cannot actually see the image. So when the user clicks download, it seems like its downloading the image, but when you click on it, it says no preview available. Image editors don't seem to be able to interpret anything either. Any suggestions?
This should work <?php $file ="http://forums.digitalpoint.com/images/misc/dps_logo.gif"; switch($ext) { case "gif": $ctype="image/gif"; break; case "png": $ctype="image/png"; break; case "jpeg": case "jpg": $ctype="image/jpg"; break; default: $ctype="application/force-download"; } header("Content-Type: $ctype"); header("Content-Disposition: attachment; filename=".basename($file)); header("Content-Transfer-Encoding: binary"); readfile($file); ?> PHP:
Technically, you cannot store files in the database. But if by file, you mean link, then yes. But remember that you have to connect the user to your database. So, if you can see the file with a URL, then you can force a download with the scripts provided above.