473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

PHP hidden download

Hello ,

I would like to ask if its possible to write an php script that allows me to dont show the actual url of file that is being downloaded . For example i have a file at www.example.com/downloads/file.zip and when an user shows to a link i would like it look sometthink like www.example.com/download.php?t=11 or somethink like that .

Thank you for your time
Feb 21 '10 #1
5 6828
Atli
5,058 Expert 4TB
Hey.

Sure, you can do that. You would just have to assign an ID or value to each file, try to match the ID or value passed to the download.php file with it's file , and serve the files from their actual locations based on that.

It's common to store files in a directory out of reach from the public, but record their location in a database. You can then use the ID of a database row in a PHP script to serve the file from the location stored in that row. That way you can put restrictions on who can or can not download a file.

P.S.
Please try to use example.com in example URLs, rather than some random domain. Random domains tend to actually exist :)
Feb 21 '10 #2
Thank you :D But i must say that i am really (but really really) new within PHP :) Started today and i know only basics . I would like to ask if s1 could be so kind to provide an example :) Thank you !
Feb 21 '10 #3
Hello well i am back again and i was searching the net but i still cant figure out how to write an proper script this is what i have so far

In html page
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. </head>
  4. <body>
  5. <a href="download.php?id=1">Download</a>
  6. </body>
  7. </html>
The script itself

Expand|Select|Wrap|Line Numbers
  1. <?
  2. $id = $_GET['id'];
  3.  
  4. if ($id = "1") {
  5. $filename = "http://www.example.com/download/file.zip";
  6. }
  7.  
  8. if ($id = "2") {
  9. $filename = "http://www.example.com/download/file1.zip";
  10. }
  11.  
  12. if ($id = "3") {
  13. $filename = "http://www.example.com/download/file2.zip";
  14. }
  15.  
  16. if ($id = "4") {
  17. $filename = "http://www.example.com/download/file3.zip";
  18. }
  19.  
  20. header("Content-disposition: attachment; filename=".$filename.""); 
  21.  
  22. header('Content-type: application/octet-stream');
  23.  
  24. readfile($filename); 
  25.  
  26. ?>
I cant figure out that it does open the download but instead of downloading the file i want it download smthink with the full adress like http://www.example.com/download/file2.zip and it has only a few bytes . Anyone know where is my mistake please? :)
Feb 22 '10 #4
It's possible to provide a link to download any file on your server without revealing the file's location with a one-click download link.
The download link requires software on your server to send the file contents to the browser. Complete software for PHP and for Perl are available in the WebSite's Secret area. Choose which you prefer to use. Only one is needed. If installing the PHP script, verify the PHP code is at the beginning of the file. As I remember from php tutorials no spaces or other characters, and no blank lines, may come before the PHP code. Otherwise, the PHP code will be unable to send header lines to the browser. Upload it to somewhere in your document directories.
When the link is clicked, the download commences. In most situations, the user will be asked where on their computer to store the file. The web page itself does not change.
Feb 23 '10 #5
Go to ParentThis is how you can hide download url in PHP:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $fakeFileName= "fakeFileName.zip";
  3. $realFileName = "realFileName.zip";
  4.  
  5. $file = "downloadFolder/".$realFileName;
  6. $fp = fopen($file, 'rb');
  7.  
  8. header("Content-Type: application/octet-stream");
  9. header("Content-Disposition: attachment; filename=$fakeFileName");
  10. header("Content-Length: " . filesize($file));
  11. fpassthru($fp);
  12. ?>
You can see all steps to hide download url here http://5ss.co/viewtopic.php?f=26&p=3
Nov 12 '15 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Glenn Owens | last post by:
As a "newbie" to Javascript I need some help with my latest problem... I have a number of image files that have been pre-selected by the user for downloading. I'd like to be able to have the user...
9
by: Randell D. | last post by:
Folks, I have a large amount of values to store (we're talking tens, if not hundreds of bytes). I need this for a client side application - ignore the security consequences for the moment -...
2
by: David R. | last post by:
Is there a way to measure and report the up/download speed between the server and the client browser using ASP.NET 2.0 C#?
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
0
by: aepheus | last post by:
I use the following code to create a file for the user to download: Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); Response.Buffer = true; Response.ContentType = "text/ris";...
107
by: bonneylake | last post by:
Hey Everyone, Well for the last few days i been trying to figure out how to delete attachments and download attachments to my computer. The deleting is sort of working and i don't know where to...
3
by: swand9 | last post by:
Hi, I need to downlad a server side generated csv file with Javascript. I need to send the login name and password and I don't want to use GET as I want to avoid a visible password in the URL....
1
by: helplakshmi | last post by:
I want to download the records of the output of search criteria to excel. As the fields for search criteria are more than 20. I am submitting the form with POST method rather than GET. On click...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.