1. PHP Script for image download you can make any file to to download
Paste this script in your file or save it download.php
<?php
$imageurl = filter_input(INPUT_GET, 'imageurl', FILTER_SANITIZE_URL);
// Clean the image URL to get the path and make sure the user is just getting an image.
$url_parsed = parse_url($imageurl);
$file = $_SERVER['DOCUMENT_ROOT'] .'/base-directory'. $url_parsed['path'];
print_r($file);
// Get the extension of the file.
$extension = substr(strrchr($file ,'.'), 1);
// Limit the extensions in this array to those you're allowing the user to download.
$allowed_extensions = array('jpg', 'jpeg', 'png', 'gif');
// Make sure the file requested is in your list of allowed extensions to make sure the user isn't downloading something other than an image.
if (in_array(strtolower($extension), $allowed_extensions)) {
if (file_exists($file)) {
header ('Content-type: octet/stream');
header ('Content-disposition: attachment; filename=' . basename($file) . ';');
header('Content-Length: ' . filesize($file));
ob_clean();
readfile($file);
}
}
?>
1. HTML Code
Paste this code in your html file
Download
Enjoy......
No comments:
Post a Comment