Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 11-10-2006, 06:32 AM   #1 (permalink)
transfield
Code Monkey
 
Join Date: Mar 2006
Posts: 35
transfield is on a distinguished road
Random URL That Expires

Hello,
I want to hide a file somewhere on my server. I then want to create a random url that will eventually expire(after a few days) which links to this file. Then I want to give this url to my customers in order for them to download the file.

I tried this tutorial at http://forums.devshed.com/php-develo...url-38357.html This code works fine & is exactly what I'm looking for. The only problem with this code is the location of the secret file is eventually revealed in this line:-
PHP Code:
// Take the user to the file: 
header("Location: http://mydomain.com/filedir/" addslashes($n)); 
So how do I hide the actual location of the file?

Thanks.
transfield is offline   Reply With Quote
Old 11-10-2006, 06:51 AM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
you may want to re-think your delivery method. how large are the files?

you could store the files below the web root and use PHP to stream the file dynamically. this would allow you to authenticate your user agains a database (or however you want to authenticate them)

when the user successfully authenticates, you can have php stream the file from below the web root directly to the user.

below is example code i found of php streaming a file.

PHP Code:
$filename // your parameter

$filename realpath($filename); //server specific

$file_extension strtolower(substr(strrchr($filename,"."),1));

if (! 
file_exists$filename ) )
{
die(
"NO FILE HERE";
};
switch( 
$file_extension )
{
case 
"pdf"$ctype="application/pdf"; break;
case 
"exe"$ctype="application/octet-stream"; break;
case 
"zip"$ctype="application/zip"; break;
case 
"doc"$ctype="application/msword"; break;
case 
"xls"$ctype="application/vnd.ms-excel"; break;
case 
"ppt"$ctype="application/vnd.ms-powerpoint"; break;
case 
"gif"$ctype="image/gif"; break;
case 
"png"$ctype="image/png"; break;
case 
"jpe": case "jpeg":
case 
"jpg"$ctype="image/jpg"; break;
default: 
$ctype="application/force-download";
}
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Type: $ctype");
header("Content-Disposition: attachment; filename=".basename($filename).";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".@filesize($filename));
@
readfile("$filename") or die("File not found.");
exit();

?> 
__________________
Mike
sde is offline   Reply With Quote
Old 11-10-2006, 07:09 AM   #3 (permalink)
transfield
Code Monkey
 
Join Date: Mar 2006
Posts: 35
transfield is on a distinguished road
Thanks for your reply, sde. It's actually a small php file. I'm providing a paid service where the user pays me for temporary usage of the features on that php file.

I appreciate your advice. I'll study it further.
transfield is offline   Reply With Quote
Old 11-10-2006, 07:19 AM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
here we go, .. i knew it was covered here before. this is a little easier to digest...

Download portal
__________________
Mike
sde is offline   Reply With Quote
Reply

Bookmarks

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
REferrencing URL from DB joehouse MS Technologies ( ASP, VB, C#, .NET ) 0 08-02-2005 02:20 PM
URL query j.gohel Java 17 04-15-2005 10:22 AM
Random Internal Server Errors ZachH PHP 6 03-14-2005 11:29 AM
Log visited URL to fileż Britomo PHP 2 07-14-2002 03:06 PM


All times are GMT -8. The time now is 11:17 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting