TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-07-2010, 04:59 PM   #1 (permalink)
The Contributor
 
Tim Dobson's Avatar
 
Join Date: Feb 2010
Posts: 69
Thanks: 16
Tim Dobson is on a distinguished road
Default file ID instead of url?

How would i go about using a file id for a download rather than giving them a direct link to the file? iv done a search on google and had no idea what this would come under... iv found site stat scripts that do this but i want to try avoid using sql databases and these require it.
Tim Dobson is offline  
Reply With Quote
Old 03-07-2010, 05:44 PM   #2 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Associate arrays.

php Code:
$arr = array( 'ze-fyle-eyed' => "{$path}/file.ext",
              'ze-other-fyle' => "{$path}/otherfile.ext" );

Return the appropriate header information and let the script send it from its 007 location to the user.
delayedinsanity is offline  
Reply With Quote
Old 03-08-2010, 02:39 AM   #3 (permalink)
bajingo
 
skibbli's Avatar
 
Join Date: Feb 2010
Posts: 11
Thanks: 2
skibbli is on a distinguished road
Default

assuming the files you'd be linking to are all in one place. you could use base64?

PHP Code:
$file base64_decode($_GET[id]);
if (
file_exist($file)) {
 
header("location: filedir/$file");
} else {
 echo 
"<title>404</title><h1>404</h1>";


Last edited by skibbli : 03-08-2010 at 04:21 AM.
skibbli is offline  
Reply With Quote
Old 03-08-2010, 04:47 AM   #4 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Using a META redirect is still giving them a direct link to the file, you don't even need any advanced tools to get the link to that one.

Why do you want to avoid using an SQL database? A good database is generally the foundation of a worthwhile dynamic script. Any other method to store data would be slower and less efficient.

There are two ways to separate the client from the content. The first is to use a database to store the files, this is not really a good method. The next is to store them below the webroot (thus no URI to access it) and use a script to bring it up if the correct accidentals are given. The first thing you do is have some sort of database (mysql, xml, it really doesn't matter) to link the IDs to the file locations on the hard drive. Next you find the ID, verify the credentials are correct then write that file to the output stream along with the meta data. I've done this in both PHP and .net where file security was an absolute must (the .net one was for a mortgage bank).

I couldn't find a tutorial on google for this (about 2 minutes of looking), but the function that reads the file is readfile. If you are on a shared server and can not put files below the webroot, pick one above the webroot but use .htaccess to deny all. I wouldn't use this workaround (or a shared server at all) for anything that would be considered a major security breach should it fail.
__________________

Village Idiot is offline  
Reply With Quote
Old 03-08-2010, 06:13 AM   #5 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Who said anything about META? Village, I think you've been hitting the bottle again.

Write a little function to determine what file is to be sent (and where its located) based on an ID passed to your script, and there's no reason you can't send any number of files from a single location.

Read in some GET that does a lookup (SQL, array, from a file, from where ever) to match the ID to the file, then send your headers and pipe that sucker through.

php Code:
if ( isset( $_GET['id'] ) )
    $file = do_something_to_determine_file( 'dont_forget_to_validate' );
else
    die( 'You missed your turn.' );

header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file");
header("Content-Type: application/zip"); // Change this to match your file type.
header("Content-Transfer-Encoding: binary");

readfile($file);

All files are transferred from a single location never giving up their location to charlie.
delayedinsanity is offline  
Reply With Quote
Old 03-08-2010, 03:13 PM   #6 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Quote:
Originally Posted by delayedinsanity View Post
Who said anything about META? Village, I think you've been hitting the bottle again.

Write a little function to determine what file is to be sent (and where its located) based on an ID passed to your script, and there's no reason you can't send any number of files from a single location.

Read in some GET that does a lookup (SQL, array, from a file, from where ever) to match the ID to the file, then send your headers and pipe that sucker through.
Did you even read my entire post? That is exactly what I recommended doing. I was referring to skibbli who recommended using the header command for location; which is a META redirect.
__________________

Village Idiot is offline  
Reply With Quote
Old 03-08-2010, 04:10 PM   #7 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

hah nope, I only know enough english to read the first two sentences of a post. When I hear META redirect, I think of the META html element though, so I just stopped reading. We all know you love your 40yr old scotch VI. Don't try to deny it. I know your level of work, and I've dealt with some of the same type of clients I know you have. It's hard not to be a little tipsy by afternoon. *hic*
delayedinsanity is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

vB 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
Easy to Modify Login Script with Hierarchical User Permissions and XML Account File Wildhoney Script Giveaway 4 05-04-2011 06:11 AM
Where is my file? superthin General 3 07-25-2009 09:48 AM
Aptana Jaxer and file uploads xenon Advanced PHP Programming 2 06-06-2008 10:22 AM
Writing to XML file buildakicker General 8 02-06-2008 08:17 PM
Using class methods in an included file? Andrew Advanced PHP Programming 6 12-23-2007 03:20 AM


All times are GMT. The time now is 09:13 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design