Current location: Hot Scripts Forums » General Community » Script Requests » Looking for script that sends email and dowloads file onlick or other


Looking for script that sends email and dowloads file onlick or other

Reply
  #1 (permalink)  
Old 11-17-10, 03:59 AM
stephenkershaw stephenkershaw is offline
New Member
 
Join Date: Nov 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Looking for script that sends email and dowloads file onlick or other

Hi

I'm not a coder so don't know how to write this myself. I'm very much of the copy and paste type.

Basically I want a file to be downloaded and an email sent when either a link is clicked or a submit button is pressed.

This is so that when a particular file hosted on my site (a pdf) is downloaded I am alerted to this by an email notification.

Can anyone help me out with this?

Thanks in advance for your help

Stephen



- Programming Language - PHP, or other that will work
- Platform - Linux / windows
- Free or Paid - free
- Type of License - freeware
Reply With Quote
  #2 (permalink)  
Old 11-17-10, 12:38 PM
Icepick.pt's Avatar
Icepick.pt Icepick.pt is offline
Newbie Coder
 
Join Date: Nov 2010
Location: Setúbal, near Lisbon
Posts: 89
Thanks: 3
Thanked 7 Times in 7 Posts
Try this one out
PHP Code:

<?php

 
// place this code inside a php file and call it f.e. "download.php"
$path $_SERVER['DOCUMENT_ROOT']."/path2file/"// change the path to fit your websites document structure
$fullPath $path.$_GET['download_file'];
 
if (
$fd fopen ($fullPath"r")) {
    
$fsize filesize($fullPath);
    
$path_parts pathinfo($fullPath);
    
$ext strtolower($path_parts["extension"]);
    switch (
$ext) {
        case 
"pdf":
        
header("Content-type: application/pdf"); // add here more headers for diff. extensions
        
header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachment' to force a download
        
break;
        default;
        
header("Content-type: application/octet-stream");
        
header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
    }
    
header("Content-length: $fsize");
    
header("Cache-control: private"); //use this to open files directly
    
while(!feof($fd)) {
        
$buffer fread($fd2048);
        echo 
$buffer;
    }
}
fclose ($fd);
exit;
// example: place this kind of link into the document where the file download is offered:
// <a href="download.php?download_file=some_file.pdf">Download here</a>
?>
I took it ou of this webpage, you may find more information about it there, or even contact it's author.

About emailing a warning, it is just a matter of adding php's mail() function somewhere inside, if the rest of the code suit's you.

Last edited by Icepick.pt; 11-17-10 at 12:44 PM.
Reply With Quote
  #3 (permalink)  
Old 11-17-10, 12:53 PM
stephenkershaw stephenkershaw is offline
New Member
 
Join Date: Nov 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Hi

I already came across this and have got it working.

Thanks for your help though

Stephen
Reply With Quote
Reply

Bookmarks

Tags
download, email


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 10:05 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.