Current location: Hot Scripts Forums » Programming Languages » PHP » Digitally 'watermark' files


Digitally 'watermark' files

Reply
  #1 (permalink)  
Old 09-02-03, 02:29 PM
Safrane Safrane is offline
Newbie Coder
 
Join Date: Sep 2003
Location: Netherlands
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Digitally 'watermark' files

I'm looking for a php solution to digitally watermark files. I'll explain the situation so maybe someone can help me.

People login to a member area. There they can download files.
At this time a file is sent to them via a script that hides the download path. When a user has downloaded the file, a log is written into a mysql table with their ip address and other info regarding the download.

My goal is to add a random unique string (doesn't really matter what kind of string) to the file before it is sent to the user. Of couse the string shouldn't render the file unusable. Also it should be possible to add it to all types of files (exe, pdf, etc.)

I plan to add that unique string to the database table too, so if anyone distributes the file illegally and I get a hold of it, I can trace the client that distributed it via that string.

I searched all over the net, but couldn't find a single solution or at least part of it to get started.

Can anyone here tell if it is possible at all and/or give me a lead?

Thanks in advance.
__________________
[AND THEN THERE WERE NONE - SAF OUT]
Reply With Quote
  #2 (permalink)  
Old 09-05-03, 09:02 AM
YourPHPPro's Avatar
YourPHPPro YourPHPPro is offline
Community VIP
 
Join Date: Aug 2003
Posts: 430
Thanks: 0
Thanked 0 Times in 0 Posts
Have you found anything to work ? If not, PM me.
Reply With Quote
  #3 (permalink)  
Old 09-05-03, 09:13 AM
Safrane Safrane is offline
Newbie Coder
 
Join Date: Sep 2003
Location: Netherlands
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Yes, I found out I can just add some string to the end of a file (with "a") without damaging the actual file, it works fine now, thanks!
__________________
[AND THEN THERE WERE NONE - SAF OUT]
Reply With Quote
  #4 (permalink)  
Old 09-08-03, 08:22 AM
Jerome Jerome is offline
Wannabe Coder
 
Join Date: Jun 2003
Location: On Earth
Posts: 177
Thanks: 0
Thanked 0 Times in 0 Posts
sound interesting ...

can you share with us ?

thks
__________________
Support me by clicking ads
@ http://atomise.blogspot.com
CHEERS
Reply With Quote
  #5 (permalink)  
Old 09-08-03, 09:02 AM
Safrane Safrane is offline
Newbie Coder
 
Join Date: Sep 2003
Location: Netherlands
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
sure no problem

As I said I have a file which controls the download sending and logging.
First a made a function that returns the unique string, I used a md5 encoding of the current date and time:
PHP Code:

function random() 

{    
    global 
$randomstring;
    
$datx mktime();
    
$randomstring md5($datx);
    return 
$randomstring;

Next I create a function to control the sending of the file. Here the random string is added...
$name represents the actual name of the file (e.g. download.exe) and $filename represents the name of the file (e.g. Download).
Also: I use a copy function to create a new file with the watermark, the location of that file is stored in the var $dest_file.
PHP Code:

function send_file($name,$filename
{
  
$status FALSE;
  
$len strlen($name);
  
$extension substr($name,$len-3,$len); 
  
$randomstring random();
  
$path "/path/to/file/".$name;
  
$dest_file "/path/to/file/".$randomstring.$name;
  
copy($path$dest_file); 
  
$fp fopen($dest_file,'a');
  if(!
$fp
  {
      echo 
"Error opening file";
      exit;
  }
  else
  {
      
fwrite($fp$randomstring);
      if(!
fclose($fp)) 
      {
        echo 
"Error closing file";
        exit;
      }            
   }
  if (!
is_file($dest_file) or connection_status()!=0) return(FALSE);
  
header("Content-type: application/octet-stream");
  
header("Content-Disposition: inline; filename=\"".$filename.".".$extension."\"");
  
header("Content-length: ".(string)(filesize($dest_file)));
  
header("Expires: ".gmdate("D, d M Y H:i:s"mktime(date("H")+2date("i"), date("s"), date("m"), date("d"), date("Y")))." GMT");
  
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
  
header("Cache-Control: no-cache, must-revalidate");
  
header("Pragma: no-cache");

  if (
$file fopen($dest_file'r')) 
 {
     while(!
feof($file) and (connection_status()==0)) 
     {
         print(
fread($file1024*8));
         
flush();
     }
     
$status = (connection_status()==0);
     
fclose($file);
     
unlink($dest_file);
 }
   return(
$status);

And finally to send the file and log stuff to the database:
PHP Code:

if (!send_file($name,$filename)) 

{
  die (
"Error sending file...");
}
else 
{
   
mysql_connect($dbserver$dbuser$dbpass)
   or die (
"Database error");
   
mysql_select_db($dbname);
    
   
$currentdate date("Y")."-".date("m")."-".date("d");
   
$currenttime date("G").":".date("i");
   
$userid $_SESSION["userid"];
    
   if (
getenv(HTTP_X_FORWARDED_FOR)) 
  {
      
$ip getenv(HTTP_X_FORWARDED_FOR); 
  }
  else 
  { 
      
$ip getenv(REMOTE_ADDR);
  }    
  
$result mysql($dbname"INSERT INTO downloads (userid, file, date, time, ip, watermark) VALUES ('$id', '$name', '$currentdate', '$currenttime', '$ip','$randomstring')") or die ("Error adding details to database.");

I know my code is quite sloppy, hope you understand how it works, I didn't write the file send code myself, I found it somewhere, and edited it to add the watermark.
If there are any questions I will try to help
__________________
[AND THEN THERE WERE NONE - SAF OUT]

Last edited by Safrane; 09-08-03 at 09:05 AM.
Reply With Quote
Reply

Bookmarks


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Automated script to delete certain files shib_s Script Requests 3 08-03-06 05:28 PM
Admin files of my program darkcarnival Website Reviews 8 09-17-03 01:07 PM
download files sasi ASP 0 09-10-03 08:29 PM
Looking for Registered Members area access to files .. script zamen Script Requests 3 09-02-03 05:44 AM
multiple Text files to html. andreas66 JavaScript 4 06-13-03 08:04 AM


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