Hide Download file URL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Xeolex
Forum Newbie
Posts: 11
Joined: Fri Nov 18, 2011 9:00 am

Hide Download file URL

Post by Xeolex »

i am beginner in php and try to make a website in php..
i want to hide the url of the download file, can any one help me do this??


please help me...
thanks
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Hide Download file URL

Post by social_experiment »

“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Xeolex
Forum Newbie
Posts: 11
Joined: Fri Nov 18, 2011 9:00 am

Re: Hide Download file URL

Post by Xeolex »

i have tryed that one, but its not working...
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Hide Download file URL

Post by twinedev »

That is pretty much it. so what isn't working? It gives you errors? It is showing file instead of downloading? What browsers are you trying it in?

-Greg
Xeolex
Forum Newbie
Posts: 11
Joined: Fri Nov 18, 2011 9:00 am

Re: Hide Download file URL

Post by Xeolex »

i am running this on my localhost using wamp server
and i am using firefox as a browser

Code: Select all

<?php
$path = 'C:/wamp/www/test.avi'; // the file made available for download via this PHP file
$mm_type="application/octet-stream"; // modify accordingly to the file type of $path, but in most cases no need to do so

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: " . $mm_type);
header("Content-Length: " .(string)(filesize($path)) );
header('Content-Disposition: attachment; filename="'.basename($path).'"');
header("Content-Transfer-Encoding: binary\n");

readfile($path); // outputs the content of the file

exit();
   ?>
its downloading the file but its only able to download 1.3kb from the file..
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Hide Download file URL

Post by twinedev »

Open the file in something like notepad++, see if it looks like a source code from a webpage that is displaying an error. If not, and the begining of that file looks the same as the actual file you are trying to get, check what value is being given for Content-Length.

-Greg
Xeolex
Forum Newbie
Posts: 11
Joined: Fri Nov 18, 2011 9:00 am

Re: Hide Download file URL

Post by Xeolex »

twinedev wrote:Open the file in something like notepad++, see if it looks like a source code from a webpage that is displaying an error. If not, and the begining of that file looks the same as the actual file you are trying to get, check what value is being given for Content-Length.

-Greg
????
i dont understand you???

i have checked the content-length and it is same as real file size..
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Hide Download file URL

Post by twinedev »

Does the 1.3kb of data you get from the download match the first 1.3kb of the file you are trying to download? if not, what is it?

Do not assume what you received from the server was the type of file you think you should be getting. Perhaps there is an error generating from the server, and what you are actually downloading is the error message the server is outputting, just named as what you thought you wanted to get.

-Greg
Xeolex
Forum Newbie
Posts: 11
Joined: Fri Nov 18, 2011 9:00 am

Re: Hide Download file URL

Post by Xeolex »

i am trying to download an avi file(movie)..
when i run the php script it starts downloading the test.avi file,but without any error the download get completed with only 1.3kb file..

thank you
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Hide Download file URL

Post by social_experiment »

Tried the code in FF and IE9; works fine. Try modifying your path where the file resides.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Hide Download file URL

Post by twinedev »

Xeolex wrote:i am trying to download an avi file(movie)..
when i run the php script it starts downloading the test.avi file,but without any error the download get completed with only 1.3kb file..

thank you
If you get an error, since you are "downloading" the output of the script, you will not see it on the screen, it will be in the file, thus, why I said to open the 1.3kb file in a text editor to see what it looks like.

-Greg
Xeolex
Forum Newbie
Posts: 11
Joined: Fri Nov 18, 2011 9:00 am

Re: Hide Download file URL

Post by Xeolex »

here is the file contant

Code: Select all

<br />
<font size='1'><table class='xdebug-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 945367041 bytes) in C:\wamp\www\test.php on line <i>15</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0008</td><td bgcolor='#eeeeec' align='right'>380496</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='C:\wamp\www\test.php' bgcolor='#eeeeec'>..\test.php<b>:</b>0</td></tr>
<tr><td bgcolor='#eeeeec' align='center'>2</td><td bgcolor='#eeeeec' align='center'>0.0013</td><td bgcolor='#eeeeec' align='right'>381464</td><td bgcolor='#eeeeec'><a href='http://www.php.net/readfile' target='_new'>readfile</a>
(  )</td><td title='C:\wamp\www\test.php' bgcolor='#eeeeec'>..\test.php<b>:</b>15</td></tr>
</table></font>
thank you..
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Hide Download file URL

Post by social_experiment »

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 945367041 bytes) in C:\wamp\www\test.php on line
There's something you can search for. Looks like the file downloaded is the error page.
http://www.tech-recipes.com/rx/777/solv ... ted-tried/
Have a look at this url

Hth
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Xeolex
Forum Newbie
Posts: 11
Joined: Fri Nov 18, 2011 9:00 am

Re: Hide Download file URL

Post by Xeolex »

its seem in my php.ini it sets to 128M

Code: Select all

memory_limit = 128M
anyone knows whats the problem??
and what can i do to overcome this error??

thanks..
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Hide Download file URL

Post by twinedev »

And how big is the file you are trying to download?

-Greg
Post Reply