PHP hidden download

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • drunreal
    New Member
    • Feb 2010
    • 3

    PHP hidden download

    Hello ,

    I would like to ask if its possible to write an php script that allows me to dont show the actual url of file that is being downloaded . For example i have a file at www.example.com/downloads/file.zip and when an user shows to a link i would like it look sometthink like www.example.com/download.php?t=11 or somethink like that .

    Thank you for your time
    Last edited by Atli; Feb 21 '10, 06:36 PM. Reason: Replace real URLs with example values.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    Sure, you can do that. You would just have to assign an ID or value to each file, try to match the ID or value passed to the download.php file with it's file , and serve the files from their actual locations based on that.

    It's common to store files in a directory out of reach from the public, but record their location in a database. You can then use the ID of a database row in a PHP script to serve the file from the location stored in that row. That way you can put restrictions on who can or can not download a file.

    P.S.
    Please try to use example.com in example URLs, rather than some random domain. Random domains tend to actually exist :)

    Comment

    • drunreal
      New Member
      • Feb 2010
      • 3

      #3
      Thank you :D But i must say that i am really (but really really) new within PHP :) Started today and i know only basics . I would like to ask if s1 could be so kind to provide an example :) Thank you !

      Comment

      • drunreal
        New Member
        • Feb 2010
        • 3

        #4
        Hello well i am back again and i was searching the net but i still cant figure out how to write an proper script this is what i have so far

        In html page
        Code:
        <html>
        <head>
        </head>
        <body>
        <a href="download.php?id=1">Download</a>
        </body>
        </html>
        The script itself

        Code:
        <?
        $id = $_GET['id'];
        
        if ($id = "1") {
        $filename = "http://www.example.com/download/file.zip";
        }
        
        if ($id = "2") {
        $filename = "http://www.example.com/download/file1.zip";
        }
        
        if ($id = "3") {
        $filename = "http://www.example.com/download/file2.zip";
        }
        
        if ($id = "4") {
        $filename = "http://www.example.com/download/file3.zip";
        }
        
        header("Content-disposition: attachment; filename=".$filename.""); 
        
        header('Content-type: application/octet-stream');
        
        readfile($filename); 
        
        ?>
        I cant figure out that it does open the download but instead of downloading the file i want it download smthink with the full adress like http://www.example.com/download/file2.zip and it has only a few bytes . Anyone know where is my mistake please? :)
        Last edited by Dormilich; Mar 5 '10, 06:22 AM. Reason: correcting URIs

        Comment

        • Teleport
          Banned
          New Member
          • Feb 2010
          • 1

          #5
          It's possible to provide a link to download any file on your server without revealing the file's location with a one-click download link.
          The download link requires software on your server to send the file contents to the browser. Complete software for PHP and for Perl are available in the WebSite's Secret area. Choose which you prefer to use. Only one is needed. If installing the PHP script, verify the PHP code is at the beginning of the file. As I remember from php tutorials no spaces or other characters, and no blank lines, may come before the PHP code. Otherwise, the PHP code will be unable to send header lines to the browser. Upload it to somewhere in your document directories.
          When the link is clicked, the download commences. In most situations, the user will be asked where on their computer to store the file. The web page itself does not change.

          Comment

          • monasinha
            New Member
            • Nov 2015
            • 1

            #6
            Go to ParentThis is how you can hide download url in PHP:

            Code:
            <?php
            $fakeFileName= "fakeFileName.zip";
            $realFileName = "realFileName.zip";
             
            $file = "downloadFolder/".$realFileName;
            $fp = fopen($file, 'rb');
             
            header("Content-Type: application/octet-stream");
            header("Content-Disposition: attachment; filename=$fakeFileName");
            header("Content-Length: " . filesize($file));
            fpassthru($fp);
            ?>
            You can see all steps to hide download url here http://5ss.co/viewtopic.php?f=26&p=3

            Comment

            Working...