win8 发表于 2016-4-2 19:13

求一个类似于Aria2的工具

有个Apache+MySQl+PHP的服务器,我只有FTP和phpmadmin的界面,不允许直接做代理服务器使用,空间配额我偶尔想用作离线下载墙边的http、ftp资源,有这样现成或者改改就能用的公具吗?我是码盲,自己感觉是下载可以用PHP調wget来做

RaidenII 发表于 2016-4-2 20:08

恐怕难。php调用外部命令一般通过shell_exec、exec、system、passthrough等等几个函数,而这几个函数一般出于安全原因是禁用的。你可以写个phpinfo传到服务器上看看disable_functions禁用了哪些函数。

win8 发表于 2016-4-2 22:12


file:///D:/prg/WizNote/My%20Knowledge/temp/1dfaf304-b418-4877-b6f5-8e4ba8e2955f_128_files/in.gifPHP Version 5.3.27



Build Date
Configure Command'./configure' '--with-mysql' '--with-mysqli' '--with-apxs2=/usr/local/apache2/bin/apxs' '--with-gd' '--with-jpeg-dir=/usr/lib' '--with-zlib' '--with-mcrypt' '--enable-mbstring' '--with-freetype-dir=/usr/include/freetype2' '--with-imap' '--with-tidy' '--with-imap-ssl' '--with-kerberos' '--with-pdo-mysql' '--with-libdir=lib64' '--libdir=/usr/lib64' '--enable-ftp' '--with-curl' '--with-openssl'
Server APIApache 2.0 Handler
Virtual Directory Supportdisabled
Configuration File (php.ini) Path/usr/lib64
Loaded Configuration File/etc/php.ini
Scan this dir for additional .ini files(none)
Additional .ini files parsed(none)
PHP API20090626
PHP Extension20090626
Zend Extension220090626
Zend Extension BuildAPI220090626,NTS
PHP Extension BuildAPI20090626,NTS
Debug Buildno
Thread Safetydisabled
Zend Memory Managerenabled
Zend Multibyte Supportdisabled
IPv6 Supportenabled
Registered PHP Streamshttps, ftps, compress.zlib, php, file, glob, data, http, ftp, phar
Registered Stream Socket Transportstcp, udp, unix, udg, ssl, sslv3, sslv2, tls
Registered Stream Filterszlib.*, convert.iconv.*, mcrypt.*, mdecrypt.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk


file:///D:/prg/WizNote/My%20Knowledge/temp/1dfaf304-b418-4877-b6f5-8e4ba8e2955f_128_files/in_2.gifThis program makes use of the Zend Scripting Language Engine:
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies

PHP CreditsConfigurationapache2handler
Apache VersionApache
Apache API Version20051115
Server Administrator
Hostname:Port
User/Groupapache(48)/500
Max RequestsPer Child: 1000 - Keep Alive: on - Max Per Connection: 1000
TimeoutsConnection: 18 - Keep-Alive: 5
Virtual ServerYes
Server Root/usr/local/apache2
Loaded Modulescore mod_authn_file mod_authn_default mod_authz_host mod_authz_groupfile mod_authz_user mod_authz_default mod_auth_basic mod_include mod_filter mod_log_config mod_env mod_unique_id mod_setenvif mod_version prefork http_core mod_mime mod_autoindex mod_asis mod_cgi mod_vhost_alias mod_negotiation mod_dir mod_actions mod_userdir mod_alias mod_so mod_rewrite mod_php5 mod_log_sql mod_log_sql_mysql mod_load


DirectiveLocal ValueMaster Value
engine11
last_modified00
xbithack00

Apache Environment
VariableValue
UNIQUE_IDVv-F71d2an8AAEnF8EcAAABK
HTTP_HOST
HTTP_CONNECTIONkeep-alive
HTTP_ACCEPTtext/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
HTTP_USER_AGENTMozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.152 Safari/537.22
HTTP_ACCEPT_ENCODINGgzip,deflate
HTTP_ACCEPT_LANGUAGEen-us,en
HTTP_ACCEPT_CHARSETiso-8859-1,*,utf-8
PATH/sbin:/usr/sbin:/bin:/usr/bin
SERVER_SIGNATUREno value
SERVER_SOFTWAREApache
SERVER_NAME
SERVER_ADDR
SERVER_PORT80
REMOTE_ADDR
DOCUMENT_ROOT/usr/local/apache2/htdocs
SERVER_ADMINsupport@d
SCRIPT_FILENAME/usr/local/ap
REMOTE_PORT51118
GATEWAY_INTERFACECGI/1.1
SERVER_PROTOCOLHTTP/1.1
REQUEST_METHODGET
QUERY_STRINGno value
REQUEST_URI/
SCRIPT_NAME

HTTP Headers Information
HTTP Request Headers
HTTP RequestGET
Host
Connectionkeep-alive
Accepttext/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-AgentMozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.152 Safari/537.22
Accept-Encodinggzip,deflate
Accept-Languageen-us,en
Accept-Charsetiso-8859-1,*,utf-8
HTTP Response Headers
X-Powered-ByPHP/5.3.27
Keep-Alivetimeout=5, max=1000
ConnectionKeep-Alive
Transfer-Encodingchunked
Content-Typetext/html

Core
PHP Version5.3.27


DirectiveLocal ValueMaster Value
allow_call_time_pass_referenceOffOff
allow_url_fopenOnOn
allow_url_includeOffOff
always_populate_raw_post_dataOffOff
arg_separator.input&&
arg_separator.output&&
asp_tagsOffOff
auto_append_fileno valueno value
auto_globals_jitOnOn
auto_prepend_fileno valueno value
browscapno valueno value
default_charsetno valueno value
default_mimetypetext/htmltext/html
define_syslog_variablesOffOff
disable_classesno valueno value
disable_functionsno valueno value
display_errorsOffOff
display_startup_errorsOffOff
doc_rootno valueno value
docref_extno valueno value
docref_rootno valueno value
enable_dlOnOn
error_append_stringno valueno value
error_logno valueno value
error_prepend_stringno valueno value
error_reporting3071130711
exit_on_timeoutOffOff
expose_phpOnOn
extension_dir/usr/lib64/php//usr/lib64/php/
file_uploadsOnOn
highlight.bg#FFFFFF#FFFFFF
highlight.comment#FF8000#FF8000
highlight.default#0000BB#0000BB
highlight.html#000000#000000
highlight.keyword#007700#007700
highlight.string#DD0000#DD0000
html_errorsOnOn
ignore_repeated_errorsOffOff
ignore_repeated_sourceOffOff
ignore_user_abortOffOff
implicit_flushOffOff
include_path.:/usr/local/apache2/htdocs/DB/.:/usr/lib64/php
log_errorsOnOn
log_errors_max_len10241024
magic_quotes_gpcOffOff
magic_quotes_runtimeOffOff
magic_quotes_sybaseOffOff
mail.add_x_headerOffOff
mail.force_extra_parametersno valueno value
mail.logno valueno value
max_execution_time1030
max_file_uploads2020
max_input_nesting_level6464
max_input_time6060
max_input_vars10001000
memory_limit35M15M
open_basedir/usr/local/apache2/:/tmp//usr/local/apache2/:/tmp/
output_bufferingno valueno value
output_handlerno valueno value
post_max_size8M8M
precision1414
realpath_cache_size16K16K
realpath_cache_ttl120120
register_argc_argvOnOn
register_globalsOffOff
register_long_arraysOnOn
report_memleaksOnOn
report_zend_debugOnOn
request_orderno valueno value
safe_modeOnOff
safe_mode_exec_dirno valueno value
safe_mode_gidOffOff
safe_mode_include_dirno valueno value
sendmail_fromroot
sendmail_path/usr/sbin/sendmail -t -i/usr/sbin/sendmail -t -i -froot
serialize_precision100100
short_open_tagOnOn
SMTPlocalhostlocalhost
smtp_port2525
sql.safe_modeOffOff
track_errorsOffOff
unserialize_callback_funcno valueno value
upload_max_filesize10M10M
upload_tmp_dir/usr/local/apache2/htdocs/tmp/usr/local/apache2/htdocs/tmp
user_dirno valueno value
user_ini.cache_ttl300300
user_ini.filename.user.ini.user.ini
variables_orderEGPCSEGPCS
xmlrpc_error_number00
xmlrpc_errorsOffOff
y2k_complianceOnOn
zend.enable_gcOnOn

ctype
ctype functionsenabled

curl
cURL supportenabled
cURL Information7.15.5
Age2
Features
AsynchDNSNo
DebugNo
GSS-NegotiateYes
IDNYes
IPv6Yes
LargefileYes
NTLMYes
SPNEGONo
SSLYes
SSPINo
krb4No
libzYes
CharConvNo
Protocolstftp, ftp, telnet, dict, ldap, http, file, https, ftps
Hostx86_64-redhat-linux-gnu
SSL VersionOpenSSL/0.9.8b
ZLib Version1.2.3

date
date/time supportenabled
"Olson" Timezone Database Version2013.3
Timezone Databaseinternal
Default timezoneEurope/Berlin


DirectiveLocal ValueMaster Value
date.default_latitude31.766731.7667
date.default_longitude35.233335.2333
date.sunrise_zenith90.58333390.583333
date.sunset_zenith90.58333390.583333
date.timezoneEurope/BerlinEurope/Berlin

dom
DOM/XMLenabled
DOM/XML API Version20031129
libxml Version2.6.26
HTML Supportenabled
XPath Supportenabled
XPointer Supportenabled
Schema Supportenabled
RelaxNG Supportenabled

ereg
Regex LibraryBundled library enabled

fileinfo
fileinfo supportenabled
version1.0.5-dev

filter
Input Validation and Filteringenabled
Revision$Id: 209a1c3c98c04a5474846e7bbe8ca72054ccfd4f $


DirectiveLocal ValueMaster Value
filter.defaultunsafe_rawunsafe_raw
filter.default_flagsno valueno value

ftp
FTP supportenabled

gd
GD Supportenabled
GD Versionbundled (2.1.0 compatible)
FreeType Supportenabled
FreeType Linkagewith freetype
FreeType Version2.2.1
GIF Read Supportenabled
GIF Create Supportenabled
JPEG Supportenabled
libJPEG Version6b
PNG Supportenabled
libPNG Version1.2.10
WBMP Supportenabled
XBM Supportenabled


DirectiveLocal ValueMaster Value
gd.jpeg_ignore_warning00

hash
hash supportenabled
Hashing Enginesmd2 md4 md5 sha1 sha224 sha256 sha384 sha512 ripemd128 ripemd160 ripemd256 ripemd320 whirlpool tiger128,3 tiger160,3 tiger192,3 tiger128,4 tiger160,4 tiger192,4 snefru snefru256 gost adler32 crc32 crc32b salsa10 salsa20 haval128,3 haval160,3 haval192,3 haval224,3 haval256,3 haval128,4 haval160,4 haval192,4 haval224,4 haval256,4 haval128,5 haval160,5 haval192,5 haval224,5 haval256,5

iconv
iconv supportenabled
iconv implementationglibc
iconv library version2.5


DirectiveLocal ValueMaster Value
iconv.input_encodingISO-8859-1ISO-8859-1
iconv.internal_encodingISO-8859-1ISO-8859-1
iconv.output_encodingISO-8859-1ISO-8859-1

imap
IMAP c-Client Version2004
SSL Supportenabled
Kerberos Supportenabled

json
json supportenabled
json version1.2.1

libxml
libXML supportactive
libXML Compiled Version2.6.26
libXML Loaded Version20626
libXML streamsenabled

mbstring
Multibyte Supportenabled
Multibyte string enginelibmbfl
HTTP input encoding translationdisabled


mbstring extension makes use of "streamable kanji code filter and converter", which is distributed under the GNU Lesser General Public License version 2.1.


Multibyte (japanese) regex supportenabled
Multibyte regex (oniguruma) backtrack checkOn
Multibyte regex (oniguruma) version4.7.1


DirectiveLocal ValueMaster Value
mbstring.detect_orderno valueno value
mbstring.encoding_translationOffOff
mbstring.func_overload00
mbstring.http_inputpasspass
mbstring.http_outputpasspass
mbstring.http_output_conv_mimetypes^(text/|application/xhtml\+xml)^(text/|application/xhtml\+xml)
mbstring.internal_encodingno valueno value
mbstring.languageneutralneutral
mbstring.strict_detectionOffOff
mbstring.substitute_characterno valueno value

mcrypt
mcrypt supportenabled
mcrypt_filter supportenabled
Version2.5.8
Api No20021217
Supported cipherscast-128 gost rijndael-128 twofish arcfour cast-256 loki97 rijndael-192 saferplus wake blowfish-compat des rijndael-256 serpent xtea blowfish enigma rc2 tripledes
Supported modescbc cfb ctr ecb ncfb nofb ofb stream


DirectiveLocal ValueMaster Value
mcrypt.algorithms_dirno valueno value
mcrypt.modes_dirno valueno value

mysql
MySQL Supportenabled
Active Persistent Links1
Active Links1
Client API version5.1.54
MYSQL_MODULE_TYPEexternal
MYSQL_SOCKET/tmp/mysql.sock
MYSQL_INCLUDE-I/usr/include/mysql
MYSQL_LIBS-L/usr/lib64 -lmysqlclient


DirectiveLocal ValueMaster Value
mysql.allow_local_infileOnOn
mysql.allow_persistentOnOn
mysql.connect_timeout6060
mysql.default_hostno valueno value
mysql.default_passwordno valueno value
mysql.default_portno valueno value
mysql.default_socket/tmp/mysql.sock/tmp/mysql.sock
mysql.default_userno valueno value
mysql.max_linksUnlimitedUnlimited
mysql.max_persistentUnlimitedUnlimited
mysql.trace_modeOffOff

mysqli
MysqlI Supportenabled
Client API library version5.1.54
Active Persistent Links0
Inactive Persistent Links0
Active Links0
Client API header version5.1.54
MYSQLI_SOCKET/tmp/mysql.sock


DirectiveLocal ValueMaster Value
mysqli.allow_local_infileOnOn
mysqli.allow_persistentOnOn
mysqli.default_hostno valueno value
mysqli.default_port33063306
mysqli.default_pwno valueno value
mysqli.default_socket/tmp/mysql.sock/tmp/mysql.sock
mysqli.default_userno valueno value
mysqli.max_linksUnlimitedUnlimited
mysqli.max_persistentUnlimitedUnlimited
mysqli.reconnectOffOff

openssl
OpenSSL supportenabled
OpenSSL Library VersionOpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
OpenSSL Header VersionOpenSSL 0.9.8e-fips-rhel5 01 Jul 2008

pcre
PCRE (Perl Compatible Regular Expressions) Supportenabled
PCRE Library Version8.32 2012-11-30


DirectiveLocal ValueMaster Value
pcre.backtrack_limit10000001000000
pcre.recursion_limit100000100000

PDO
PDO supportenabled
PDO driversmysql, sqlite, sqlite2

pdo_mysql
PDO Driver for MySQLenabled
Client API version5.1.54


DirectiveLocal ValueMaster Value
pdo_mysql.default_socket/var/lib/mysql/mysql.sock/var/lib/mysql/mysql.sock

pdo_sqlite
PDO Driver for SQLite 3.xenabled
SQLite Library3.7.7.1

Phar
Phar: PHP Archive supportenabled
Phar EXT version2.0.1
Phar API version1.1.1
SVN revision$Id: 21d763042eb5769ae0a09dc1118df2b5aae6fb33 $
Phar-based phar archivesenabled
Tar-based phar archivesenabled
ZIP-based phar archivesenabled
gzip compressionenabled
bzip2 compressiondisabled (install pecl/bz2)
Native OpenSSL supportenabled


Phar based on pear/PHP_Archive, original concept by Davey Shafik.
Phar fully realized by Gregory Beaver and Marcus Boerger.
Portions of tar implementation Copyright (c) 2003-2009 Tim Kientzle.


DirectiveLocal ValueMaster Value
phar.cache_listno valueno value
phar.readonlyOnOn
phar.require_hashOnOn

posix
Revision$Id: 5a2da3946b96c5afbf3aff8db8a8681f8bedee85 $

Reflection
Reflectionenabled
Version$Id: 4af6c4c676864b1c0bfa693845af0688645c37cf $

session
Session Supportenabled
Registered save handlersfiles user sqlite
Registered serializer handlersphp php_binary


DirectiveLocal ValueMaster Value
session.auto_startOffOff
session.bug_compat_42OffOff
session.bug_compat_warnOnOn
session.cache_expire180180
session.cache_limiternocachenocache
session.cookie_domainno valueno value
session.cookie_httponlyOffOff
session.cookie_lifetime00
session.cookie_pathno valueno value
session.cookie_secureOffOff
session.entropy_fileno valueno value
session.entropy_length00
session.gc_divisor10001000
session.gc_maxlifetime14401440
session.gc_probability11
session.hash_bits_per_character44
session.hash_function00
session.namePHPSESSIDPHPSESSID
session.referer_checkno valueno value
session.save_handlerfilesfiles
session.save_path/tmp/tmp
session.serialize_handlerphpphp
session.use_cookiesOnOn
session.use_only_cookiesOnOn
session.use_trans_sid00

SimpleXML
Simplexml supportenabled
Revision$Id: 02ab7893b36d51e9c59da77d7e287eb3b35e1e32 $
Schema supportenabled

SPL
SPL supportenabled
InterfacesCountable, OuterIterator, RecursiveIterator, SeekableIterator, SplObserver, SplSubject
ClassesAppendIterator, ArrayIterator, ArrayObject, BadFunctionCallException, BadMethodCallException, CachingIterator, DirectoryIterator, DomainException, EmptyIterator, FilesystemIterator, FilterIterator, GlobIterator, InfiniteIterator, InvalidArgumentException, IteratorIterator, LengthException, LimitIterator, LogicException, MultipleIterator, NoRewindIterator, OutOfBoundsException, OutOfRangeException, OverflowException, ParentIterator, RangeException, RecursiveArrayIterator, RecursiveCachingIterator, RecursiveDirectoryIterator, RecursiveFilterIterator, RecursiveIteratorIterator, RecursiveRegexIterator, RecursiveTreeIterator, RegexIterator, RuntimeException, SplDoublyLinkedList, SplFileInfo, SplFileObject, SplFixedArray, SplHeap, SplMinHeap, SplMaxHeap, SplObjectStorage, SplPriorityQueue, SplQueue, SplStack, SplTempFileObject, UnderflowException, UnexpectedValueException

SQLite
SQLite supportenabled
PECL Module version2.0-dev $Id$
SQLite Library2.8.17
SQLite Encodingiso8859


DirectiveLocal ValueMaster Value
sqlite.assoc_case00

sqlite3
SQLite3 supportenabled
SQLite3 module version0.7-dev
SQLite Library3.7.7.1


DirectiveLocal ValueMaster Value
sqlite3.extension_dirno valueno value

standard
Dynamic Library Supportenabled
Path to sendmail/usr/sbin/sendmail -t -i -froot


DirectiveLocal ValueMaster Value
assert.active11
assert.bail00
assert.callbackno valueno value
assert.quiet_eval00
assert.warning11
auto_detect_line_endings00
default_socket_timeout6060
fromno valueno value
safe_mode_allowed_env_varsPHP_PHP_
safe_mode_protected_env_varsLD_LIBRARY_PATHLD_LIBRARY_PATH
url_rewriter.tagsa=href,area=href,frame=src,input=src,form=fakeentrya=href,area=href,frame=src,input=src,form=fakeentry
user_agentno valueno value

tidy
Tidy supportenabled
libTidy Release11 February 2007
Extension Version2.0 ($Id$)


DirectiveLocal ValueMaster Value
tidy.clean_output00
tidy.default_configno valueno value

tokenizer
Tokenizer Supportenabled

xml
XML Supportactive
XML Namespace Supportactive
libxml2 Version2.6.26

xmlreader
XMLReaderenabled

xmlwriter
XMLWriterenabled

zlib
ZLib Supportenabled
Stream Wrapper supportcompress.zlib://
Stream Filter supportzlib.inflate, zlib.deflate
Compiled Version1.2.3
Linked Version1.2.3


DirectiveLocal ValueMaster Value
zlib.output_compressionOffOff
zlib.output_compression_level-1-1
zlib.output_handlerno valueno value

Additional Modules
Module Name

Environment
VariableValue
TERMxterm
LD_LIBRARY_PATH/usr/local/apache2/lib:
PATH/sbin:/usr/sbin:/bin:/usr/bin
PWD/
LANGde_DE.UTF-8
SHLVL1
_/usr/local/apache2/bin/httpd

PHP Variables
VariableValue
_SERVER["UNIQUE_ID"]Vv-F71d2an8AAEnF8EcAAABK
_SERVER["HTTP_HOST"]
_SERVER["HTTP_CONNECTION"]keep-alive
_SERVER["HTTP_ACCEPT"]text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
_SERVER["HTTP_USER_AGENT"]Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.152 Safari/537.22
_SERVER["HTTP_ACCEPT_ENCODING"]gzip,deflate
_SERVER["HTTP_ACCEPT_LANGUAGE"]en-us,en
_SERVER["HTTP_ACCEPT_CHARSET"]iso-8859-1,*,utf-8
_SERVER["PATH"]/sbin:/usr/sbin:/bin:/usr/bin
_SERVER["SERVER_SIGNATURE"]no value
_SERVER["SERVER_SOFTWARE"]Apache
_SERVER["SERVER_NAME"]
_SERVER["SERVER_ADDR"]87.
_SERVER["SERVER_PORT"]80
_SERVER["REMOTE_ADDR"]121.
_SERVER["DOCUMENT_ROOT"]/usr/local/apache2/htdocs
_SERVER["SERVER_ADMIN"]
_SERVER["SCRIPT_FILENAME"]/usr/local/apache2
_SERVER["REMOTE_PORT"]51118
_SERVER["GATEWAY_INTERFACE"]CGI/1.1
_SERVER["SERVER_PROTOCOL"]HTTP/1.1
_SERVER["REQUEST_METHOD"]GET
_SERVER["QUERY_STRING"]no value
_SERVER["REQUEST_URI"]/
_SERVER["SCRIPT_NAME"]
_SERVER["PHP_SELF"]
_SERVER["REQUEST_TIME"]1459602927
_SERVER["argv"]Array()
_SERVER["argc"]0
_ENV["TERM"]xterm
_ENV["LD_LIBRARY_PATH"]/usr/local/apache2/lib:
_ENV["PATH"]/sbin:/usr/sbin:/bin:/usr/bin
_ENV["PWD"]/
_ENV["LANG"]de_DE.UTF-8
_ENV["SHLVL"]1
_ENV["_"]/usr/local/apache2/bin/httpd

PHP License
This program is free software; you can redistribute it and/or modify it under the terms of the PHP License as published by the PHP Group and included in the distribution in the file: LICENSE
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
If you did not receive a copy of the PHP license, or have any questions about PHP licensing, please contact license@php.net.



RaidenII 发表于 2016-4-2 22:29

这个可能是chroot过或者httpd关掉了那些函数……试试用php-curl来实现吧,用exec调用wget或者fopen打开url都不是很安全。
这个应该可以:https://stackoverflow.com/questions/4000483/how-download-big-file-using-php-low-memory-usage

win8 发表于 2016-4-3 00:32

RaidenII 发表于 2016-4-2 22:29
这个可能是chroot过或者httpd关掉了那些函数……试试用php-curl来实现吧,用exec调用wget或者fopen打开url ...

非常感谢你的范例,我改了一个建议界面,已经代测试OK。比较纠结的是下载进度没有界面查看
,也没有办法取消下载中的任务。/**
* Copy remote file over HTTP one small chunk at a time.
*
* @param $infile The full URL to the remote file
* @param $outfile The path where to save the file
*/

<form method="post">
<input name="url" size="50" />
<input name="submit" type="submit" />
</form>

<?php

//maximum execution time in seconds
set_time_limit (24 * 60 * 60);
if (!isset($_POST['submit'])) die();
// folder to save downloaded files to. must end with slash
   $destination_folder = '/prg/phpStudyLite/tmp/';
//$destination_folder = '下载路径';
$url = $_POST['url'];
$newfname = $destination_folder . basename($url);
copyfile_chunked($url ,$newfname);


function copyfile_chunked($infile, $outfile) {
    $chunksize = 10 * (1024 * 1024); // 10 Megs

    /**
   * parse_url breaks a part a URL into it's parts, i.e. host, path,
   * query string, etc.
   */
    $parts = parse_url($infile);
    $i_handle = fsockopen($parts['host'], 80, $errstr, $errcode, 5);
    $o_handle = fopen($outfile, 'wb');

    if ($i_handle == false || $o_handle == false) {
      return false;
    }

    if (!empty($parts['query'])) {
      $parts['path'] .= '?' . $parts['query'];
    }

    /**
   * Send the request to the server for the file
   */
    $request = "GET {$parts['path']} HTTP/1.1\r\n";
    $request .= "Host: {$parts['host']}\r\n";
    $request .= "User-Agent: Mozilla/5.0\r\n";
    $request .= "Keep-Alive: 115\r\n";
    $request .= "Connection: keep-alive\r\n\r\n";
    fwrite($i_handle, $request);

    /**
   * Now read the headers from the remote server. We'll need
   * to get the content length.
   */
    $headers = array();
    while(!feof($i_handle)) {
      $line = fgets($i_handle);
      if ($line == "\r\n") break;
      $headers[] = $line;
    }

    /**
   * Look for the Content-Length header, and get the size
   * of the remote file.
   */
    $length = 0;
    foreach($headers as $header) {
      if (stripos($header, 'Content-Length:') === 0) {
            $length = (int)str_replace('Content-Length: ', '', $header);
            break;
      }
    }

    /**
   * Start reading in the remote file, and writing it to the
   * local file one chunk at a time.
   */
    $cnt = 0;
    while(!feof($i_handle)) {
      $buf = '';
      $buf = fread($i_handle, $chunksize);
      $bytes = fwrite($o_handle, $buf);
      if ($bytes == false) {
            return false;
      }
      $cnt += $bytes;

      /**
         * We're done reading when we've reached the conent length
         */
      if ($cnt >= $length) break;
    }

    fclose($i_handle);
    fclose($o_handle);
    return $cnt;
}

?>
页: [1]
查看完整版本: 求一个类似于Aria2的工具