i want to create a save button for save image on desktop

Discussion in 'PHP' started by dineshsingh1984, Jul 19, 2011.

  1. #1
    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,
     
    dineshsingh1984, Jul 19, 2011 IP
  2. techbongo

    techbongo Active Member

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    80
    #2
    
    // 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:
     
    techbongo, Jul 21, 2011 IP
  3. dineshsingh1984

    dineshsingh1984 Active Member

    Messages:
    154
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    thanks for code but how can use on save button plz describe to me..........

    thanks..........
     
    dineshsingh1984, Jul 21, 2011 IP
  4. dthoai

    dthoai Member

    Messages:
    106
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    38
    #4
    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):
     
    dthoai, Jul 22, 2011 IP
  5. exodus

    exodus Well-Known Member

    Messages:
    1,900
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    165
    #5
    
    <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.
     
    exodus, Jul 22, 2011 IP
  6. techbongo

    techbongo Active Member

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    80
    #6
    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.
     
    techbongo, Jul 22, 2011 IP