Xplorer4x4
Xplorer4x4

Reputation: 1

File Size Calculated but File Not Found

I am trying to install the "Waiting time file download script using php and jquery" script found at http://www.w3webtools.com/simple-page-download-file-using-php-and-jquery/

I have downloaded the demo scripts and installed them in my server at /var/www/test/.

When I try to call the demo files it recognizes the file size but says the file is not found. http://4x4submods.tk/test/download.php?f=advance-security-login-system-using-php-mysql.zip

Any ideas?

mod_rewrite is enabled.

Upvotes: 0

Views: 203

Answers (1)

Zast
Zast

Reputation: 502

This works:

<?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 file:

<?php
function makeHash($fileName)
{
    return md5( $fileName . SECURITY_CODE );
}
function verifyHash($fileName,$hashCode)
{
    return $hashCode==makeHash($fileName);
}

Ensure that you use the same hash that you used in the key when decoding!

The rest was not really required and made it more complicated than necessary!

Including the file date in the hash, may make it not work if the file date changes for some reason, for example, if you need to do a system restore. You can probably put the server name back in the hash if you think you really want it!

Upvotes: 0

Related Questions