Results 1 to 6 of 6

Thread: Email download like like siteground.com

  1. #1
    Join Date
    Apr 2008
    Location
    Little Office!
    Posts
    80
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default Email download like like siteground.com

    when we go to this page http://www.siteground.com/order_temp...452&download=1 to download the template... We get an email with a download link which is only valid for 15 mins.

    i want this same thing to happen. I know there is some database thing and php coding invloved... please help!

  2. #2
    Join Date
    Apr 2008
    Location
    Little Office!
    Posts
    80
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    help pleasE!

  3. #3
    Join Date
    Apr 2008
    Location
    Little Office!
    Posts
    80
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    where are all the xperts!

  4. #4
    Join Date
    Jun 2009
    Location
    UK
    Posts
    19
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default

    First, don't prompt people to help you... people will help you if they want to or not it's totally optional =).

    First up, you will need a simple php file, to fetch the download data from within the MySQL DB. Then send the end-user an e-mail with a simple download link, which again will expire within let's say 24 hours from the download was requested.

    To be honest, it's not always recommended to set it as 15 minutes because that's just ridiculous and not always will people speed for a download!

    Anyways, let's call this file "downloadfile.php".

    PHP Code:
    <?php

    $fileID 
    $_GET['fileID']; //change to whatever!
    $uemail $_GET['email']; //change to whatever!

    if (isset($_GET['fileID'])){

    //Include a connection to the MySQL Database

    include("../dbconnect.inc.php"); //Connect File, also change location to the connect file

    //We need to perform a simple MySQL Query

    $query mysql_query("SELECT * FROM files WHERE fileID = '$fileID' LIMIT 1") or die('Unable to perform the MySQL Query: ' mysql_error());
    $resul mysql_query($query) or die('Unable to perform the MySQL Query: ' mysql_error());
    $numrows mysql_num_rows($resul);

    //We'll check to wherever the file actually exists in the db.

    if ($numrows == 0){//failed
    echo "Unable to find the file requested!";
    }

    //We need to extract some data from the db.

    $rows mysql_fetch_array($resul);

    $fileName $rows["file_name"]; //The name of the file
    $fileLocation $rows["file_location"]; //The location of the file, e.g. www.mysite.com/files/template_black.zip
    $fileID $rows["fileID"]; //The file ID
    $hash "abcdefghijklmnopqrstwxy123456789ABCDEFGHIJKLMNOPQRSTWXY";
    $mhash md5($hash);

    //Now we got our data, we'll insert into another DB

    $insert mysql_query("INSERT INTO fileReady (filename, filelocation, mhash, fileID) VALUES('$fileName','$fileLocation','$mhash','$fileID')") or die('error: ' mysql_error());

    if(
    $insert){//success

    //let's send the user the e-mail

    $fileLink "http://www.yoursite.com/templates/downloadfile.php?fileID=$fileID&mid=$mhash&getfile=1";

    $to "$uemail";
    $subject "Requested template from www.yoursite.com!";
    $message "
    Template: 
    $fileName is ready to be downloaded (download link expire within 24 hours)\n\n
    $fileLink\n\n
    Thank you for downloading from us!!!
    "
    ;
    $headers "From: you <you@yoursite.com>\nReply-To: you <you@yoursite.com>";

    //Now send the e-mail

    mail($to$subject$message$headers);

    //Now we'll set a cookie to expire in 24 hours with the file mhash and filename.

    $expire time()+60*60*24//Set to expire in 24 hours!
    setcookie($fileName$fileLink$expire);

    }

    if(isset(
    $_GET['getfile'])){

    //Now for for the download

    $fileQuery mysql_query("SELECT * FROM fileReady WHERE fileID = '$fileID'") or die('error: ' mysql_error());
    $resulQy   mysql_query($fileQuery) or die('error: ' mysql_error());
    $numrows   mysql_num_rows($resulQy);

    if(
    $numrows == 0){//not found
    echo "Not Found?";
    }

    //extract the data

    $get mysql_fetch_array($resulQy);

    $fileLocation $get["filelocation"];

    header("Content-Type: application/force-download");
    header("Content-Disposition: attachment; filename=".basename($filelocation));
    header("Content-Description: File Transfer");

    }
    }
    ?>
    This is only a snippet i coded, and isn't secure whatsoever therefore it should really be learned by and not used as it could cause server security issues or worse MySQL injections, i've provided this as a snippet to help you so there

    BTW: It's been tested and works, but again follow what I said above it's UNSECURE! Unless your willing to learn about security on PHP, once you got a basic knowledge of security side, put some security into this code and you'll be ready to go!

    Hope this helps

  5. #5
    Join Date
    Apr 2008
    Location
    Little Office!
    Posts
    80
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    it never helped!

  6. #6
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    totally helped!! thank you

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •