Forum Moderators: coopster

Message Too Old, No Replies

PHP and MySQL Linking Problem

Need help with link diversion with My SQL DB and download.php file

         

AlexB77

1:34 am on Aug 3, 2009 (gmt 0)

10+ Year Member Top Contributors Of The Month



I need to hide a real file name by using random names that will refer visitor to the actual folder directory were the original file is located.

What I am trying to create is:

Download Now link on one page that will look like this -<a href=”http://www.example.com/dl.php?urlid=absdef”>Download Now</a> and like
this- http://www.example.com/fileDownload/dl.php?filename=myFile.zip or like this - http://www.example.com/fileDownload/myFile.zip

I have been told that I need to create a table in My SQL DB that will contain urlid along with Original File Names and random names assigned to each file.

In my understanding it will probably look like the table below:

URL IDOriginal File Name Random File Name
001Personal-budget-calculator.xlsPersonalbudget
002Home-budget.xls Household
003Purchase-order.xls purchaseorder

How to do it all this is my question?

I believe that this is something that can be done since I have seen on many other web sites furthermore this can also be used to hide your affiliate ID links under some random name in urls.

[edited by: dreamcatcher at 6:55 am (utc) on Aug. 3, 2009]
[edit reason] use example.com. Thanks. [/edit]

andrewsmd

1:37 pm on Aug 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What specifically do you need help on. "How to do it all" is not good to post because most people will ignore your post if you put that. Try to get started on it and post back when you have a problem. I would try to set up a couple records in the database that have the appropriate data and see if you can get one correct.

AlexB77

3:32 pm on Aug 3, 2009 (gmt 0)

10+ Year Member Top Contributors Of The Month



This ie exactly what I need. I can create a simple table but that will look like the one above, but I do not know how to make a connection in beetween in the row. for example if you line id is "PersonalBudget" and you click on the download link that's looking like this <a href="http://yoursite.com/download.php?urlid=PersonalBudget">Download Now</a> so than it will start the download of the file "Personal-budget-calculator.xls" without even showing the folder were original file is located.

This would probably be my first question: How can I make a connection between Random Names and Original file names in MySQL DB?

Thanks in advance

andrewsmd

4:53 pm on Aug 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You would probably use the $_GET variables. You would have a generic download page. Let's call it download.php. Now in download.php you would have code like

<?php

$encryptedFileName = $_GET['fileName'];

//now do your mysql connection
//the query would look something like this
//assuming your table is in the following structure
//id ¦ FileName ¦ Encryption

$query = "select FileName from TableOfFiles where Encryption = '{$encryptedFileName}';";

//do your mysql connection here and store the result as
//$fileName

//then set your header content
//take a note I don't know what the mime type for an
//xls file is, you will have to look on your server
//and make sure it is supported.
//alternatively you could try this
//header("Content-type: application/octet-stream");
//instead of header("Content-type: application/xls");
header("Content-type: application/xls");
header("Content-Disposition: attachment; filename=theNameYouWantHere.xls");
readfile("{$fileName}");

?>