Jump to content

Htaccess


ajicles

Recommended Posts

I know that .htaccess is php. But I need help with my website that is file hosting. I need a way for people to download the file and not just use a direct link to the file. So I though I could use htaccess to stop that. But that is a main issue. I need some way for php to grab the file without being blocked by htaccess and place it into a temp folder then allow for download. But the only issue with that is the user could leave the website when the download is downloading. But I could have a script that will delete the temp file when it expires. But then how would it run if there is no user on the website  >:( I could try making it when a person comes to the site it deletes the file if it is expired but then again if there is zero traffic it will never expire.

 

Any thoughts to my situation?

 

Another thing I need help is making a download button appear when the timer hits zero. I tried using javascript to make a hidden div to show with the download button in it. But then the user can just look at the source code and see the link...

 

So many loop holes  >:(

Link to comment
Share on other sites

.htaccess file

deny from all

 

Create that in Notepad if on Windows (lets you save files with a . in front) and put that in the /files directory. That will block direct access to the file. PHP can still access the file though.

 

Then all you need to do in your PHP is navigate to the directory where the file is and you should be able to open it using PHP and make it available for download.

 

Well that's what I'd try and do, might be wrong though.

Link to comment
Share on other sites

Any thoughts to my situation?

I'd go for Azsen's solution.

 

Another thing I need help is making a download button appear when the timer hits zero. I tried using javascript to make a hidden div to show with the download button in it. But then the user can just look at the source code and see the link...

Try using ajax - jquery framework will be easiest form of ajax to use for this. This can load the html returned from a PHP file into a div on the page. You can script this to show a count down, then when it finishes load the PHP file to the div. The php can then check if the timeout has passed, through a session value showing the time when the download page was first clicked.

Link to comment
Share on other sites

I think you have the wrong idea about downloading files. All you need to do is place the files outside of the publicly accessible directory (e.g. outside of htdocs / public_html / or whatever your web server names it) and then use PHP to read the file and force download.

 

 

I know that .htaccess is php.

Actually .htaccess files are for configuration of Apache, not PHP (although you can modify certain PHP config options though them).

Link to comment
Share on other sites

typo "isn't".

 

 

 

Aloso

I have found a script with a count down timer:

if (!empty($message)) {
echo "<p class=\"message\">" . $message . "</p>";
}
else
{
	 if (!@$_GET['d']){
 redirect_to("index.php");
}
else
{	 
echo '
<div id="downloadingform">


<center>
<p><center>Please until the countdown is done, or upgrade your account.</center></p>
<p><center>You are downloading: '.$row[1].'</center></p>
<p> </p>
<p>  </p>
<form name="counter"><center><input type="text" size="8" 
name="d2"></center></form> 

<script> 
<!-- 
// 
var milisec=0 
var seconds=30 
document.counter.d2.value="30" 

function display(){ 
if (milisec<=0){ 
    milisec=9 
    seconds-=1 
} 
if (seconds<=-1){ 
    milisec=0 
    seconds+=1 
} 
else 
    milisec-=1 
    document.counter.d2.value=seconds+"."+milisec 
    setTimeout("display()",100) 
} 
display() 
--> 
</script> 


<div id="hid" style="visibility:hidden"><center><a href="upload/'.$row[4].'/'.$row[1].'"><img src="images/download.png" width="200" height="55" border="0" /></a></center></div>
<script type="text/javascript">
function showIt() {
  document.getElementById("hid").style.visibility = "visible";
}
setTimeout("showIt()", 30000); // after 1 sec
</script>





</div>';

Link to comment
Share on other sites

I tried using:

 

			$file = $row['1'];		
		header("Pragma: public");
		header("Expires: 0");
		header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 

		header("Content-Type: application/force-download");
		header( "Content-Disposition: attachment; filename=".basename($_SERVER['DOCUMENT_ROOT'].'FileHosting/upload/'.$row[4].'/'.$file));

		header( "Content-Description: File Transfer");
		@readfile($file);

 

When I echo back: $_SERVER['DOCUMENT_ROOT'].'FileHosting/upload/'.$row[4].'/'.$file

 

It gives me this: D:/wamp/www/FileHosting/upload/ajicles/040810051842songs.txt

 

Which is the right location and file.

 

But it returns this:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<title>Ajicles File Hosting - Downloading:040810051842songs.txt</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<!--[if IE 6]>
<link rel="stylesheet" type="text/css" href="iecss.css" />
<![endif]-->
</head>
<body>
<div id="main_container">
  <div id="header">
    <div id="logo"><a href="index.html"><img src="images/logo.png" alt="" title="" border="0" width="251" height="82"/></a></div>
    <div id="menu_tab">
      <ul class="menu">
        <li><a href="index.php" class="nav"> Home </a></li>
        <li><a href="upload.php" class="nav"> Upload</a></li>
        <li><a href="login.php" class="nav"> Login</a></li>
        <li><a href="register.php" class="nav"> Register</a></li>
        <li><a href="contact.php" class="nav"> Contact </a></li>
        <li><a href="logout.php" class="nav"> Logout </a></li>
      </ul>
    </div>
  </div>
  <div id="main_content">
    <div id="downloading">
          </div>
  </div>
  <div class="clear"></div>
</div>
<!-- main_content-->

<div id="footer"> <img src="images/footer_logo.gif" alt="" title="" width="33" height="45" class="left" />
  <div class="left_footer"> Ajicles Hosting 2010. All Rights Reserved </div>
</div>
</div>
</body>
</html>

 

I don't know what I am doing wrong?  :shrug::confused:

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.