i want to create a save button for save image on desktop. how can do this plz give the script which are work at all browser........... plz help me.... plzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz it's urgent, so plz..........asap............ thanks,
// force to download a file $file = "http://localhost/test/image_file_name.jpg"; header("Pragma: public"); header("Expires: 0"); header("Content-Type: application/force-download"); header( "Content-Disposition: attachment; filename=".basename($file)); header( "Content-Description: File Transfer"); @readfile($file); ?> PHP:
You catch click event of Save button, then open url of download page. See following codes: <input type='button' value='Save' onclick="location='http://yourhost/forcedownload.php';" /> Code (markup):
<a href="savebuttonfile.php" target="_blank"><img src="savebutton.png"></a> Code (markup): Why could you not just do it like this? You would have the force download in the .php file. It would open up another window so perhaps a javascript onlick event would be better as dthoai said.
Save the following code in a file - download.php on your server. Run it with appropriate URL. <?php if(isset($_GET['download'])) { // force to download a file $file = "http://localhost/test/image_file_name.jpg"; header("Pragma: public"); header("Expires: 0"); header("Content-Type: application/force-download"); header( "Content-Disposition: attachment; filename=".basename($file)); header( "Content-Description: File Transfer"); @readfile($file); } else { ?> <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input type="submit" name="download" value="Download File" /> </form> <?php } ?> PHP: Ensure that the if() part inside the PHP code doesn't output any blank space (whitespace) apart from the image file.