我正在尝试在http://www.w3webtools.com/simple-page-download-file-using-php-and-jquery/
上安装“使用php和jquery等待时间文件下载脚本”脚本我已下载演示脚本并将其安装在/var/www/test/
的服务器中。
当我尝试调用演示文件时,它会识别文件大小,但表示找不到该文件。 http://4x4submods.tk/test/download.php?f=advance-security-login-system-using-php-mysql.zip
有什么想法吗?
启用mod_rewrite。
答案 0 :(得分:0)
这有效:
<?php
header('Content-Type: text/html;charset=UTF-8');
include 'include/config.php';
include 'include/function.php';
?>
<!-- Edited to point to the latest copy of jquery! -->
<script src="http://code.jquery.com/jquery-2.0.0.js"></script><?php
$fname='hello.txt';
$download=1;
if(!file_exists(UPLOAD_DIR.'/'.$fname))
{
$download=0;
}
$downloadLink='download/'.makeHash($fname).'/'.$fname;
function file_size($url){
$size = filesize($url);
if($size >= 1073741824){
$fileSize = round($size/1024/1024/1024,1) . 'GB';
}elseif($size >= 1048576){
$fileSize = round($size/1024/1024,1) . 'MB';
}elseif($size >= 1024){
$fileSize = round($size/1024,1) . 'KB';
}else{
$fileSize = $size . ' bytes';
}
return $fileSize;
}
?>
<div class="container">
<span class="filename" id="fileinfo-filename" title="<?=$fname?>"><?=$fname?></span>
<span class="fileinfo" id="fileinfo">File Size: <span id="fileinfo-filesize"><?php
if($download!=0){
echo file_size(UPLOAD_DIR.'/'.$fname);
}else{
echo 'N/A';
}
?></span> - Your IP: <span id="fileinfo-views"><?=$_SERVER['REMOTE_ADDR'];?></span></span>
<div id="btnX" class="btn btn-blue">
<span class="text1" id="countdown-info">PREPARERING DOWNLOAD...</span>
<span class="timedown" id="countdown-time"></span>
</div>
<div id="<?=$download?>" class="loading" style="display: none;"></div>
<input id="download" type="text" style="display: none;" value="<?php echo $download ?>">
<a class="btn btn-green" id="btn-download" style="display: none;" href="<?=$downloadLink?>">
<span class="text2">DOWNLOAD</span>
</a>
</div>
<script type="text/javascript">
http://w3webtools.com/wp-admin/post-new.php#
var countDown;
jQuery(document).ready(function(){
countDown=function(start){
if(start==0)
{
jQuery('#countdown-time').html('');
jQuery('#countdown-info').html('PREPARERING DOWNLOAD...');
bla = $('#download').val();
if(bla==0){
jQuery('#countdown-info').html('ERROR: Press F5 to try again. <br></br>404: File not found!');
}else{
jQuery('#btnX').css('display','none');
jQuery('#btn-download').css('display','inline-block');
}
return true;
}
jQuery('#countdown-time').html(start+'s');
start--;
setTimeout('countDown('+start+')',1000);
}
countDown(5);
});
</script>
Function.php文件:
<?php
function makeHash($fileName)
{
return md5( $fileName . SECURITY_CODE );
}
function verifyHash($fileName,$hashCode)
{
return $hashCode==makeHash($fileName);
}
确保在解码时使用您在密钥中使用的相同哈希值!
其余的并不是真正需要的,并且使它比必要的更复杂!
如果文件日期因某种原因发生变化(例如,如果您需要进行系统还原),则将文件日期包含在散列中可能会使其无效。如果您认为自己真的需要,可以将服务器名称放回哈希值中!