473,499 Members | 1,525 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP hidden download

3 New Member
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 6839
Atli
5,058 Recognized Expert Expert
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
drunreal
3 New Member
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
drunreal
3 New Member
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
Teleport
1 New Member
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
monasinha
1 New Member
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
18914
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
4216
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
2711
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
6918
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
812
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
11207
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
5015
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
2146
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
7130
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7220
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6893
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5468
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4599
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3098
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3090
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
664
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.