因此,即时通讯工作在Windows系统,虽然这在本地工作,知道它会打破其他人民服务器。请告诉我一个跨平台的方式做同样的,因为这最好的方法来写这个函数。它得到一个远程文件,并复制它本地,在php
function fetch($get,$put){
file_put_contents($put,file_get_contents($get));
}
因此,即时通讯工作在Windows系统,虽然这在本地工作,知道它会打破其他人民服务器。请告诉我一个跨平台的方式做同样的,因为这最好的方法来写这个函数。它得到一个远程文件,并复制它本地,在php
function fetch($get,$put){
file_put_contents($put,file_get_contents($get));
}
这里会使用简单的文件操作的解决方案:
<?php
$file = "http://www.domain.com/thisisthefileiwant.zip";
$hostfile = fopen($file, 'r');
$fh = fopen("thisisthenameofthefileiwantafterdownloading.zip", 'w');
while (!feof($hostfile)) {
$output = fread($hostfile, 8192);
fwrite($fh, $output);
}
fclose($hostfile);
fclose($fh);
?>
确保您的目录启用写入权限。 (CHMOD)
因此,对于您的更换取($得到,$ PUT)将是:
function fetch($get, $put) {
$hostfile = fopen($get, 'r');
$fh = fopen($put, 'w');
while (!feof($hostfile)) {
$output = fread($hostfile, 8192);
fwrite($fh, $output);
}
fclose($hostfile);
fclose($fh);
}
希望它帮助! =)
干杯, KRX
我不明白为什么,除非其他计算机上PHP4会失败。你需要做的,使该向后兼容的功能添加到提供的file_get_contents更换什么& file_put_contents:
if(version_compare(phpversion(),'5','<')) {
function file_get_contents($file) {
// mimick functionality here
}
function file_put_contents($file,$data) {
// mimick functionality here
}
}
如果是v4 vs v5问题,http://pear.php.net/package/PHP_Compat有file_put_contents()(file_get_contents在v4.3 +中) – 2009-04-12 08:38:26
肖恩的答案是绝对正确的,唯一的事情是,你需要确保你的$放在Unix服务器上的Windows Server上,可变的是有效的路径。
很好,当我读了你的问题我理解你希望把从远程服务器的文件保存到本地服务器,这可以用FTP扩展从PHP
http://www.php.net/manual/en/function.ftp-fget.php
来完成,如果这不是你的意图,我相信什么什么肖恩说的是正确的
别人告诉我的意见,我会帮你更
如果未启用fopen封装,curl扩展可能是:http://php.net/curl
为什么将它放在其他的人打破的服务器?只要Fopen包装启用,上面就会起作用。 – 2009-04-12 06:36:16