Autor Zpráva
Silver8000
Profil
Ahoj lidi prosim porad te,

Udelal jsem si stahovac na stahovani vzdalenych souboru.

Doma mi jede uplne perfektne ale kdyz jsem ho dal na server tak nejede...
Nevite cim to muze byt?

Zde prikladam cele kody :
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Simple Form Handling Through AJAX</title>
     <script src="http://code.jquery.com/jquery-latest.js"></script>
        <script>               
            $(document).ready(function() {
         $("#countStatDiv").load("getTable.php");
                 var refreshId = setInterval(function() {
                 $("#countStatDiv").load("getTable.php");
                 }, 2000);
                 $.ajaxSetup({ cache: false });
              });
          </script>
<script type="text/javascript">
    function loadXmlDoc(fname){
        var xmlhttp;
        if (window.XMLHttpRequest){
            xmlhttp = new XMLHttpRequest();
        }
        else{
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function(){
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
                document.getElementById("ajaxify").innerHTML =                xmlhttp.responseText;
            }
        }
        xmlhttp.open("POST", "remote_download.php", true);
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttp.send("url=" + fname);
    }
</script>
</head>

 <body>
<p>
<div align="center">
<form  id="frm" action="" method="post">
    <input type="text" name="url" size="50"/>
    <input type="button" value="submit" onclick="loadXmlDoc(url.value)" />
</form>
    <div id="countStatDiv" style="height:50px;"></div>
    <div id="ajaxify" style="height:50px;"></div>
</div>
</p>
</body>
</html>

getTable.php

<?php
session_start();
$percent = @$_SESSION['percent_uploaded'];
$local_file_size = @$_SESSION['local_file_size'];
$remote_file_size = @$_SESSION['remote_file_size'];
if($percent){
//print_r($_SESSION);
$left_file_size = round(($remote_file_size-$local_file_size)/1024/1024);
$right_file_size = round(($local_file_size)/1024/1024);
if($left_file_size){
$size_info = <<<SIZEINFO
Still need to download : $left_file_size MB
SIZEINFO;
}else{
$size_info = <<<SIZEINFO
You have downloaded :  $right_file_size MB
SIZEINFO;
}
echo <<<INFO
<div style="background-color: red; width:100px; border: 1px solid black;">
<div style="background-color: green; color: white; font-weight:bold; max-width: 100px; width:{$percent}px;">
<div align="center">{$percent}%</div>
</div>
</div>
$size_info
INFO;
}
?>

remote_download.php

<?php
    // maximum execution time in seconds
set_time_limit(24 * 60 * 60);
include('remote_file_size.php');
include('format_size.php');
if (@$_POST['url']){
    // folder to save downloaded files to. must end with slash
    $destination_folder = 'downloads/';
 if (!file_exists($destination_folder)){
   mkdir($destination_folder);
 }
    $url = $_POST['url'];
$remote_file_size = remote_file_size($url);
    $newfname = $destination_folder . basename($url).'.part';
$set_speed = 1024*8;
// Total processes
//echo $remote_file_size.'<br />';
    $file = fopen ($url, "rb");
    if ($file) {
      $newf = fopen ($newfname, "wb");
 $readf = fopen($newfname, 'rb');
      if ($newf)
      while(!feof($file)) {
        fwrite($newf, fread($file, $set_speed), $set_speed);
fseek($readf, 0, SEEK_END);
$local_file_size = ftell($readf);
    // Calculate the percentation
$percent = intval(($local_file_size/$remote_file_size) * 100);
//echo $percent.' processed. '.file_size($local_file_size);
session_start();
$_SESSION['percent_uploaded'] = $percent;
$_SESSION['local_file_size'] = $local_file_size;
$_SESSION['remote_file_size'] = $remote_file_size;
session_write_close();
      }
    }
 
    if ($file) {
      fclose($file);
    }
 
    if ($newf) {
      fclose($newf);
    }
    if ($readf) {
      fclose($readf);
    }
// Sleep one second so we can see the delay
    sleep(1);
if(rename($newfname,str_replace('.part','',$newfname))){
$downloaded_size = file_size($remote_file_size);
echo 'Process completed '.$downloaded_size;
}
}
?>

remote_file_size.php

<?php
function remote_file_size($url){
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_NOBODY, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
    curl_exec($ch);
    $filesize = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
    curl_close($ch);
    if ($filesize) return $filesize;
}
?>

format_size.php
<?php
function file_size($val){
$fsizebyte = $val;
    if ($fsizebyte < 1024) {
        $fsize = $fsizebyte." bytes";
    }elseif (($fsizebyte >= 1024) && ($fsizebyte < 1048576)) {
        $fsize = round(($fsizebyte/1024), 2);
        $fsize = $fsize." KB";
    }elseif (($fsizebyte >= 1048576) && ($fsizebyte < 1073741824)) {
        $fsize = round(($fsizebyte/1048576), 2);
        $fsize = $fsize." MB";
    }elseif ($fsizebyte >= 1073741824) {
        $fsize = round(($fsizebyte/1073741824), 2);
        $fsize = $fsize." GB";
    };
return $fsize;
}
?>
DJ Miky
Profil
tak nejede“ znamená přesně co? Co se stane a nestane? Jaká chybová hláška se vypíše?
Silver8000
Profil
no stahovac nestahuje a zadna chybova hlaska se nezobrazi...
Pokusne demo zde
Taky jsem myslel ze je to kvuli allow_url_fopen ale neni ten je povolen.

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm: