コード例 #1
0
 /**
  * @param string $file
  * @return int
  */
 public function size($file)
 {
     return $this->ftp->filesize($file);
 }
コード例 #2
0
function getftpurl($host, $port, $url, $saveToFile = 0)
{
    global $nn, $lastError, $PHP_SELF, $AUTH, $IS_FTP, $FtpBytesTotal, $FtpBytesReceived, $FtpTimeStart, $FtpChunkSize, $options;
    $ftp = new ftp(FALSE, FALSE);
    if (!$ftp->SetServer($host, (int) $port)) {
        $ftp->quit();
        $server = $host . ':' . $port;
        $lastError = sprintf(lang(79), $server) . "<br />" . '<a href="javascript:history.back(-1);">' . lang(78) . '</a><br /><br />';
        return FALSE;
    } else {
        if (!$ftp->connect()) {
            $ftp->quit();
            $lastError = sprintf(lang(79), $server) . "<br />" . '<a href="javascript:history.back(-1);">' . lang(78) . '</a><br /><br />';
            return FALSE;
        } else {
            if (!$ftp->login($AUTH["ftp"]["login"], $AUTH["ftp"]["password"])) {
                $ftp->quit();
                $lastError = lang(80) . "<br />" . '<a href="javascript:history.back(-1);">' . lang(78) . '</a><br /><br />';
                return FALSE;
            } else {
                echo '<p>';
                printf(lang(81), $host);
                echo '<br />';
                //$ftp->Passive(FALSE);
                $tmp = explode("/", $url);
                $ftp_file = array_pop($tmp);
                $ftp_dir = implode("/", $tmp);
                $ftp->chdir($ftp_dir);
                $fileSize = $FtpBytesTotal = $ftp->filesize($ftp_file);
                $FtpChunkSize = round($fileSize / 333);
                list($saveToFile, $tmp) = explode('?', $saveToFile);
                if (!empty($options['rename_prefix'])) {
                    $File_Name = $options['rename_prefix'] . '_' . basename($saveToFile);
                    $saveToFile = dirname($saveToFile) . PATH_SPLITTER . $File_Name;
                }
                if (!empty($options['rename_suffix'])) {
                    $ext = strrchr(basename($saveToFile), ".");
                    $before_ext = explode($ext, basename($saveToFile));
                    $File_Name = $before_ext[0] . '_' . $options['rename_suffix'] . $ext;
                    $saveToFile = dirname($saveToFile) . PATH_SPLITTER . $File_Name;
                }
                if ($options['rename_underscore']) {
                    $File_Name = str_replace(array(' ', '%20'), '_', basename($saveToFile));
                    $saveToFile = dirname($saveToFile) . PATH_SPLITTER . $File_Name;
                }
                $filetype = strrchr($saveToFile, ".");
                if (is_array($options['forbidden_filetypes']) && in_array(strtolower($filetype), $options['forbidden_filetypes'])) {
                    if ($options['forbidden_filetypes_block']) {
                        html_error(sprintf(lang(82), $filetype));
                    } else {
                        $saveToFile = str_replace($filetype, $options['rename_these_filetypes_to'], $saveToFile);
                    }
                }
                if (file_exists($saveToFile)) {
                    $saveToFile = dirname($saveToFile) . PATH_SPLITTER . time() . "_" . basename($saveToFile);
                }
                printf(lang(83), $saveToFile, bytesToKbOrMbOrGb($fileSize));
                echo "<br />";
                ?>
<br />
<table cellspacing="0" cellpadding="0" style="FONT-FAMILY: Tahoma; FONT-SIZE: 11px;">
<tr>
<td></td>
<td>
<div class="progressouter">
<div id="progress" class="ftpprogress">
</div>
</div>
</td>
<td></td>
<tr>
<tr>
<td align="left" id="received">0 KB</td>
<td align="center" id="percent">0%</td>
<td align="right" id="speed">0 KB/s</td>
</tr>
</table>
<br />
<div id="resume" align="center" style="FONT-FAMILY: Tahoma; FONT-SIZE: 11px;"></div>
<script type="text/javascript">
/* <![CDATA[ */
function pr(percent, received, speed){
	document.getElementById("received").innerHTML = '<b>' + received + '</b>';
	document.getElementById("percent").innerHTML = '<b>' + percent + '%</b>';
	document.getElementById("progress").style.width = percent + '%';
	document.getElementById("speed").innerHTML = '<b>' + speed + ' KB/s</b>';
	document.title = 'Downloaded ' + percent + '%';
	return true;
	}

	function mail(str, field) {
	document.getElementById("mailPart." + field).innerHTML = str;
	return true;
	}
/* ]]> */
</script>
<br />
<?php 
                $FtpTimeStart = getmicrotime();
                if ($ftp->get($ftp_file, $saveToFile)) {
                    return array("time" => sec2time(round($time)), "speed" => @round($FtpBytesTotal / 1024 / (getmicrotime() - $FtpTimeStart), 2), "received" => TRUE, "size" => bytesToKbOrMbOrGb($fileSize), "bytesReceived" => $FtpBytesReceived, "bytesTotal" => $FtpBytesTotal, "file" => $saveToFile);
                } else {
                    return FALSE;
                }
                $ftp->quit();
            }
        }
    }
}
コード例 #3
0
ファイル: ftp.php プロジェクト: SheppeR/rapidleech
function getftpurl($host, $port, $url, $saveToFile = 0)
{
    global $nn, $lastError, $PHP_SELF, $FtpBytesTotal, $FtpBytesReceived, $FtpTimeStart, $FtpChunkSize, $options;
    $ftp = new ftp(FALSE, FALSE);
    $server = "{$host}:{$port}";
    if (empty($host) || empty($port) || !$ftp->SetServer($host, (int) $port)) {
        $ftp->quit();
        $lastError = sprintf(lang(79), $server);
        return FALSE;
    } else {
        if (!$ftp->connect()) {
            $ftp->quit();
            $lastError = sprintf(lang(79), $server);
            return FALSE;
        } else {
            if (!$ftp->login()) {
                $ftp->quit();
                $lastError = lang(80);
                return FALSE;
            } else {
                echo '<p>';
                printf(lang(81), $server);
                echo '<br />';
                //$ftp->Passive(FALSE);
                $tmp = explode("/", $url);
                $ftp_file = array_pop($tmp);
                $ftp_dir = implode('/', $tmp);
                $ftp->chdir($ftp_dir);
                $fileSize = $FtpBytesTotal = $ftp->filesize($ftp_file);
                $FtpChunkSize = round($fileSize / 333);
                if (strpos($saveToFile, '?') !== false) {
                    $saveToFile = substr($saveToFile, 0, strpos($saveToFile, '?'));
                }
                if ($options['file_size_limit'] > 0) {
                    if ($fileSize > $options['file_size_limit'] * 1024 * 1024) {
                        $lastError = lang(336) . bytesToKbOrMbOrGb($options['file_size_limit'] * 1024 * 1024) . ".";
                        return false;
                    }
                }
                if (!empty($options['rename_prefix'])) {
                    $File_Name = $options['rename_prefix'] . '_' . basename($saveToFile);
                    $saveToFile = dirname($saveToFile) . PATH_SPLITTER . $File_Name;
                }
                if (!empty($options['rename_suffix'])) {
                    $ext = strrchr(basename($saveToFile), '.');
                    $before_ext = explode($ext, basename($saveToFile));
                    $File_Name = $before_ext[0] . '_' . $options['rename_suffix'] . $ext;
                    $saveToFile = dirname($saveToFile) . PATH_SPLITTER . $File_Name;
                }
                if ($options['rename_underscore']) {
                    $File_Name = str_replace(array(' ', '%20'), '_', basename($saveToFile));
                    $saveToFile = dirname($saveToFile) . PATH_SPLITTER . $File_Name;
                }
                $filetype = strrchr($saveToFile, '.');
                if (is_array($options['forbidden_filetypes']) && in_array(strtolower($filetype), $options['forbidden_filetypes'])) {
                    if ($options['forbidden_filetypes_block']) {
                        html_error(sprintf(lang(82), $filetype));
                    }
                    $saveToFile = str_replace($filetype, $options['rename_these_filetypes_to'], $saveToFile);
                }
                if (@file_exists($saveToFile) && $options['bw_save']) {
                    // Skip in audl.
                    if (isset($_GET['audl'])) {
                        echo '<script type="text/javascript">parent.nextlink();</script>';
                    }
                    html_error(lang(99) . ': ' . link_for_file($saveToFile));
                } elseif (@file_exists($saveToFile)) {
                    $saveToFile = dirname($saveToFile) . PATH_SPLITTER . time() . '_' . basename($saveToFile);
                }
                printf(lang(83), basename($saveToFile), bytesToKbOrMbOrGb($fileSize));
                echo "<br />";
                require_once TEMPLATE_DIR . '/transloadui.php';
                $FtpTimeStart = getmicrotime();
                if ($ftp->get($ftp_file, $saveToFile)) {
                    $ftp->quit();
                    $time = getmicrotime() - $FtpTimeStart;
                    return array('time' => sec2time(round($time)), 'speed' => @round($FtpBytesTotal / 1024 / $time, 2), 'received' => TRUE, 'size' => bytesToKbOrMbOrGb($fileSize), 'bytesReceived' => $FtpBytesReceived, 'bytesTotal' => $FtpBytesTotal, 'file' => $saveToFile);
                }
                $ftp->quit();
                return FALSE;
            }
        }
    }
}
コード例 #4
0
ファイル: ftp.php プロジェクト: laiello/rapidleech36b
function getftpurl($host, $port, $url, $saveToFile = 0)
{
    global $nn, $lastError, $PHP_SELF, $FtpBytesTotal, $FtpBytesReceived, $FtpTimeStart, $FtpChunkSize, $options, $L;
    $ftp = new ftp(FALSE, FALSE);
    $server = "{$host}:{$port}";
    if (empty($host) || empty($port) || !$ftp->SetServer($host, (int) $port)) {
        $ftp->quit();
        $lastError = $L->sprintf($L->say['couldnt_establish_con'], $server) . "<br />" . '<a href="javascript:history.back(-1);">' . $L->say['_back'] . '</a><br /><br />';
        return FALSE;
    } else {
        if (!$ftp->connect()) {
            $ftp->quit();
            $lastError = $L->sprintf($L->say['couldnt_establish_con'], $server) . "<br />" . '<a href="javascript:history.back(-1);">' . $L->say['_back'] . '</a><br /><br />';
            return FALSE;
        } else {
            if (!$ftp->login()) {
                $ftp->quit();
                $lastError = $L->say['incorrect_userpass'] . "<br />" . '<a href="javascript:history.back(-1);">' . $L->say['_back'] . '</a><br /><br />';
                return FALSE;
            } else {
                echo '<p>';
                $L->sprintf($L->say['_con'], $host);
                echo '<br />';
                //$ftp->Passive(FALSE);
                $tmp = explode("/", $url);
                $ftp_file = array_pop($tmp);
                $ftp_dir = implode("/", $tmp);
                $ftp->chdir($ftp_dir);
                $fileSize = $FtpBytesTotal = $ftp->filesize($ftp_file);
                $FtpChunkSize = round($fileSize / 333);
                if (strpos($saveToFile, '?') !== false) {
                    $saveToFile = substr($saveToFile, 0, strpos($saveToFile, '?'));
                }
                if ($options['maxlimitsize'] > 0) {
                    if ($fileSize > $options['maxlimitsize'] * 1024 * 1024) {
                        $lastError = $L->sprintf($L->say['_sorry_tobig'], bytesToKbOrMbOrGb($fileSize), $options["maxlimitsize"]);
                        return false;
                    }
                }
                if ($options['minlimitsize'] > 0) {
                    if ($fileSize < $options['minlimitsize'] * 1024 * 1024) {
                        $lastError = $L->sprintf($L->say['_sorry_tosmall'], bytesToKbOrMbOrGb($fileSize), $options["minlimitsize"]);
                        return false;
                    }
                }
                if (!empty($options["add_ext_5city"]) || !empty($options['rename_suffix']) || !empty($options['rename_prefix']) || $options['rename_underscore']) {
                    if (!empty($options["add_ext_5city"])) {
                        $ext = str_replace(".", "", $options["add_ext_5city"]);
                        $File_Name = basename($saveToFile) . "." . $options["add_ext_5city"];
                    }
                    if (!empty($options['rename_prefix'])) {
                        $File_Name = $options['rename_prefix'] . '_' . basename($saveToFile);
                    }
                    if (!empty($options['rename_suffix'])) {
                        $ext = strrchr(basename($saveToFile), ".");
                        $before_ext = explode($ext, basename($saveToFile));
                        $File_Name = $before_ext[0] . '_' . $options['rename_suffix'] . $ext;
                    }
                    if ($options['rename_underscore']) {
                        $File_Name = str_replace(array(' ', '%20'), '_', basename($saveToFile));
                    }
                    $saveToFile = dirname($saveToFile) . PATH_SPLITTER . $File_Name;
                }
                $filetype = strrchr($saveToFile, ".");
                if (is_array($options['forbidden_filetypes']) && in_array(strtolower($filetype), $options['forbidden_filetypes'])) {
                    if ($options['forbidden_filetypes_block']) {
                        html_error($L->sprintf($L->say['_forbid_filetype'], $filetype));
                    } else {
                        $saveToFile = str_replace($filetype, $options['rename_these_filetypes_to'], $saveToFile);
                    }
                }
                if (file_exists($saveToFile)) {
                    $saveToFile = dirname($saveToFile) . PATH_SPLITTER . time() . "_" . basename($saveToFile);
                }
                if (!empty($options["add_ext_5city"])) {
                    $ext = "." . get_extension(basename($saveToFile));
                    $File_Name = str_replace($ext, "", basename($saveToFile));
                }
                echo $L->sprintf($L->say['_saveprogres'], $saveToFile, $ext, bytesToKbOrMbOrGb($fileSize)) . "<br />";
                require_once TEMPLATE_DIR . 'transloadui.php';
                $FtpTimeStart = getmicrotime();
                if ($ftp->get($ftp_file, $saveToFile)) {
                    $ftp->quit();
                    $time = getmicrotime() - $FtpTimeStart;
                    return array('time' => sec2time(round($time)), 'speed' => @round($FtpBytesTotal / 1024 / $time, 2), 'received' => TRUE, 'size' => bytesToKbOrMbOrGb($fileSize), 'bytesReceived' => $FtpBytesReceived, 'bytesTotal' => $FtpBytesTotal, 'file' => $saveToFile);
                }
                $ftp->quit();
                return FALSE;
            }
        }
    }
}