Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
get an email->send a encoded url->download a pdf
Old 10-25-2010, 12:33 PM get an email->send a encoded url->download a pdf
Novice Talker

Posts: 5
Name: steve
Trades: 0
Hi,

I would an script to give a free PDF as a gift:

1. get an email on a box on my website (like the newsletter subscriptions)
2. send an email to subscriber, with a confirmation url
3. after confirmation, the user will receive a new email, getting a PDF to download (from my localhost, but encoding the url)

Any idea? . I have mailman installed on my server, but i need a more specific solution.

Thank you for your time,

Steve,
stevemail is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-25-2010, 01:47 PM Re: get an email->send a encoded url->download a pdf
Justinwiz's Avatar
Skilled Talker

Posts: 58
Name: Justin
Location: /etc/httpd/logs/error_log
Trades: 0
Quote:
Originally Posted by stevemail View Post
Hi,

I would an script to give a free PDF as a gift:

1. get an email on a box on my website (like the newsletter subscriptions)
2. send an email to subscriber, with a confirmation url
3. after confirmation, the user will receive a new email, getting a PDF to download (from my localhost, but encoding the url)

Any idea? . I have mailman installed on my server, but i need a more specific solution.

Thank you for your time,

Steve,


PHP Code:
<?php
//Configurable Options:
$URL =  ""//URL to the script. Example: http://mydomain.com/scripts/downloadpd.php (Enter between the quotes)
$dlLink ""//The file you want  to be downloaded. Example: http://mydomain.com/downloads/awesome.pdf (Enter between the quotes)

if(isset($_GET['key'])) {
$filename "keys.txt";
$handle fopen($filename"r");
$contents fread($handlefilesize($filename));
fclose($handle);
if(
substr_count($contents,$_GET['key']) == 1) {
echo 
"Your download link <a href='" $dlLink "'>Download</a>";
} else {
echo 
"Invalid key";
}
} else if(isset(
$_POST['email'])) {
function 
genRandomString() {
    
$length 26;
    
$characters '0123456789abcdefghijklmnopqrstuvwxyz';
    
$string '';   

    for (
$p 0$p $length$p++) {
        
$string .= $characters[mt_rand(0strlen($characters))];
    }

    return 
$string;
}

$randKey genRandomString();
echo 
$randKey;
$fileName="keys.txt";
$file fopen ($fileName"a");
fwrite($file$randKey);
fclose ($file);
mail($_POST['email'], 'Download your PDF''Hello, please visit the following URL to download your PDF ' $URL '?key=' '' $randKey);
echo 
"Check your inbox for the download link.";
} else {
?>
<form action="" method="POST">
Email: <input type="text" name="email"><br>
<input type="submit">
</form>
<?php
}
?>
The above script I made should work, I have not implemented security measures.

All you need to do is create a file called keys.txt and chmod it to 777.

As for the URL encoding (Like Uppit does for example, to prevent people giving the direct link) you could copy the file into a directory and give a link to that, then have a cronjob that checks every file the the directory, and if the creation date is more than 48 hours ago, it deletes it.
I could give an example if you want, just ask.

Enjoy
__________________
█ Reliable VPS and Minecraft server hosting at extremely affordable prices.

Please login or register to view this content. Registration is FREE

Last edited by Justinwiz; 10-25-2010 at 01:51 PM..
Justinwiz is offline
Reply With Quote
View Public Profile
 
Old 10-25-2010, 02:48 PM Re: get an email->send a encoded url->download a pdf
Novice Talker

Posts: 5
Name: steve
Trades: 0
Thanks a lot, JustinWiz! I downloaded now, and it runs ok, receiving the link on the customer email. Just a question more; in order to save the email adress, would be great to add it on a raw text file, an email by line... (no SQL inserts). Thanks again! Steve,
stevemail is offline
Reply With Quote
View Public Profile
 
Old 10-25-2010, 03:09 PM Re: get an email->send a encoded url->download a pdf
Justinwiz's Avatar
Skilled Talker

Posts: 58
Name: Justin
Location: /etc/httpd/logs/error_log
Trades: 0
Quote:
Originally Posted by stevemail View Post
Thanks a lot, JustinWiz! I downloaded now, and it runs ok, receiving the link on the customer email. Just a question more; in order to save the email adress, would be great to add it on a raw text file, an email by line... (no SQL inserts). Thanks again! Steve,

Here is an updated version that adds the email address to a text file too.

PHP Code:
<?php
//Configurable Options:
$URL =  ""//URL to the script. Example: http://mydomain.com/scripts/downloadpd.php (Enter between the quotes)
$dlLink ""//The file you want  to be downloaded. Example: http://mydomain.com/downloads/awesome.pdf (Enter between the quotes)

if(isset($_GET['key'])) {
$filename "keys.txt";
$handle fopen($filename"r");
$contents fread($handlefilesize($filename));
fclose($handle);
if(
substr_count($contents,$_GET['key']) == 1) {
echo 
"Your download link <a href='" $dlLink "'>Download</a>";
} else {
echo 
"Invalid key";
}
} else if(isset(
$_POST['email'])) {
function 
genRandomString() {
    
$length 26;
    
$characters '0123456789abcdefghijklmnopqrstuvwxyz';
    
$string '';   

    for (
$p 0$p $length$p++) {
        
$string .= $characters[mt_rand(0strlen($characters))];
    }

    return 
$string;
}

$randKey genRandomString();
//echo $randKey; //[Debug] This shows the code being generated, currently commentened out.
$fileName="keys.txt";
$file fopen ($fileName"a");
fwrite($file$randKey);
fclose ($file);
$fileNameA="emails.txt";
$fileA fopen ($fileNameA"a");
fwrite($fileA$_POST['email'] . "\n");
fclose ($fileA);
mail($_POST['email'], 'Download your PDF''Hello, please visit the following URL to download your PDF ' $URL '?key=' '' $randKey);
echo 
"Check your inbox for the download link.";
} else {
?>
<form action="" method="POST">
Email: <input type="text" name="email"><br>
<input type="submit">
</form>
<?php
}
?>

Add emails.txt in the same directory and chmod it to 777, it saves the emails line by line.

If you need any more help, just ask me
__________________
█ Reliable VPS and Minecraft server hosting at extremely affordable prices.

Please login or register to view this content. Registration is FREE
Justinwiz is offline
Reply With Quote
View Public Profile
 
Old 10-25-2010, 03:39 PM Re: get an email->send a encoded url->download a pdf
Novice Talker

Posts: 5
Name: steve
Trades: 0
Thanks again. Please, a third (and final question). I would to insert/embed this download.php into the main file, index.php. I've tried using something like this; include("http://path to my template/.../download.php") into index.php. Another way could be to post only the form, but i don't know how. Thanks for all!, STeve.
stevemail is offline
Reply With Quote
View Public Profile
 
Old 10-25-2010, 08:05 PM Re: get an email->send a encoded url->download a pdf
Justinwiz's Avatar
Skilled Talker

Posts: 58
Name: Justin
Location: /etc/httpd/logs/error_log
Trades: 0
Quote:
Originally Posted by stevemail View Post
Thanks again. Please, a third (and final question). I would to insert/embed this download.php into the main file, index.php. I've tried using something like this; include("http://path to my template/.../download.php") into index.php. Another way could be to post only the form, but i don't know how. Thanks for all!, STeve.
You could embed it with an iframe, this way it'll load separately from the rest of your page and still look like it's part of it, here's an example:

HTML Code:
<iframe src="PATH TO SCRIPT" border="0" scrolling="no" width="350">You browser must support frames!</iframe>
__________________
█ Reliable VPS and Minecraft server hosting at extremely affordable prices.

Please login or register to view this content. Registration is FREE

Last edited by Justinwiz; 10-25-2010 at 08:09 PM..
Justinwiz is offline
Reply With Quote
View Public Profile
 
Old 10-26-2010, 05:12 AM Re: get an email->send a encoded url->download a pdf
Novice Talker

Posts: 5
Name: Sieger
Trades: 0
Why not use the 'Infinite Responder' script? It's pre-built, and you can use it to do automatic or manual follow ups in the future.
__________________

Please login or register to view this content. Registration is FREE
sieger82 is offline
Reply With Quote
View Public Profile
 
Old 10-27-2010, 12:28 PM Re: get an email->send a encoded url->download a pdf
Novice Talker

Posts: 5
Name: steve
Trades: 0
Hi again (i not finish yet...),

Nice and useful script for me. Iframe is a good solution too, and now i'm using to embed it. Just some little questions more:

1. How break lines (\n not...) inside body message into:
mail
($_POST['email'], 'Download your PDF', 'Hello, please visit the following URL to download your PDF ' . $URL . '?key=' . '' . $randKey);
echo
"Check your inbox for the download link.";

2. In the form action, i would to re-style the classic submit button to #3.
<form action="" method="POST">
Email: <input type="text" name="email"><br>
<input type="submit">


3. I'm using a 2.0 styled 'download' buttons. The idea is to substitute the 'submit' buttom of the form, by this kind of buttons:

<div class="btn"><a href="http://unaidea.org/#"><span class="btn_l">Descarregar en .PDF</span><span class="btn_r"></span></a><a href="http://unaidea.org/#">
<span class="btn_l">Descarregar en .ePUB</span><span class="btn_r"></span></a></div>

4. The final provided link to download (after click on email) returns to a newpage. It's possible to provide this echo to the same iframe?
echo "Your download link <a href='" . $dlLink . "'>Download</a>";

5. Thanks, thanks, thanks. This project is for a website concerned to give a non-profit ebook.

Steve,


Last edited by chrishirst; 10-27-2010 at 03:37 PM..
stevemail is offline
Reply With Quote
View Public Profile
 
Old 10-27-2010, 12:30 PM Re: get an email->send a encoded url->download a pdf
Novice Talker

Posts: 5
Name: steve
Trades: 0
Sorry, first item should say 'how' not 'hot'... Steve,
stevemail is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to get an email->send a encoded url->download a pdf
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.29693 seconds with 12 queries