我可以用php在本地磁盘上访问web吗?

我可以用php在本地磁盘上访问web吗?,php,Php,有一个免费的ftp空间xxx.yyy.zzz,我用filezilla将代码(名为getweb.php)上传到其中 <?php $word=file_get_contents('http://www.webkaka.com/'); $filename='c:\\file.txt'; $fh=fopen($filename,"w"); echo fwrite($fh,$word); fclose($fh); ?> 当我输入xxx.yyy.zzz\getweb.php时,我发

有一个免费的ftp空间xxx.yyy.zzz,我用filezilla将代码(名为getweb.php)上传到其中

<?php
$word=file_get_contents('http://www.webkaka.com/'); 
$filename='c:\\file.txt'; 
$fh=fopen($filename,"w");
echo  fwrite($fh,$word);
fclose($fh);
?> 

当我输入xxx.yyy.zzz\getweb.php时,我发现在我的ftp空间中有一个名为
c:\file.txt
的文件,我不得不用filezilla下载它

<?php
$word=file_get_contents('http://www.webkaka.com/'); 
$filename='c:\\file.txt'; 
$fh=fopen($filename,"w");
echo  fwrite($fh,$word);
fclose($fh);
?> 
我可以用python实现这一点,如何用php代码将网页直接捕获到本地磁盘中?

如果您使用的是PHP5,则可以使用文件内容:

file_put_contents('/path/to/file.txt', $word);

如果希望PHP代码能够在本地创建文件,则必须在本地计算机上安装PHP。如果您不想安装本机应用程序,可以尝试一个准备运行的XAMP包。

使用PHP内置的FTP流下载文件的代码

// the file your trying to get
$file ="ftp://ftp_user:ftp_pass@domain.com/file.txt";

// get the file
$contents = file_get_contents($file);
// the file your trying to get
$file ="http://domain.com/file.txt";

// get the file
$contents = file_get_contents($file);

使用PHP内置HTTP流下载文件的代码

// the file your trying to get
$file ="ftp://ftp_user:ftp_pass@domain.com/file.txt";

// get the file
$contents = file_get_contents($file);
// the file your trying to get
$file ="http://domain.com/file.txt";

// get the file
$contents = file_get_contents($file);
在远程FTP上上载(放置)文件的代码

// get the file from LOCAL HARD DRIVE
$contents = file_get_contents('C:/local/path/to/file.txt');

// the file your trying to UPLOAD
$file ="ftp://ftp_user:ftp_pass@domain.com/file.ext";

// write USING FTP
$opts = array('ftp' => array('overwrite' => true));
$context = stream_context_create($opts);
file_put_contents($file, $contents, NULL, $context);
或者结合以上几种:使用FTP下载,使用FTP上传

// the file your trying to get
$file ="ftp://ftp_user:ftp_pass@domain-ONE.com/file.txt";

// get the file USING FTP
$contents = file_get_contents($file);

// the file your trying to UPLOAD
$file ="ftp://ftp_user:ftp_pass@domain-TWO.com/file.ext";

// write USING FTP
$opts = array('ftp' => array('overwrite' => true));
$context = stream_context_create($opts);
file_put_contents($file, $contents, NULL, $context);
// the file your trying to get
$file ="http://domain-ONE.com/file.txt";

// get the file USING HTTP
$contents = file_get_contents($file);

// the file your trying to UPLOAD
$file ="ftp://ftp_user:ftp_pass@domain-TWO.com/file.ext";

// write USING FTP
$opts = array('ftp' => array('overwrite' => true));
$context = stream_context_create($opts);
file_put_contents($file, $contents, NULL, $context);
使用HTTP下载,使用FTP上载

// the file your trying to get
$file ="ftp://ftp_user:ftp_pass@domain-ONE.com/file.txt";

// get the file USING FTP
$contents = file_get_contents($file);

// the file your trying to UPLOAD
$file ="ftp://ftp_user:ftp_pass@domain-TWO.com/file.ext";

// write USING FTP
$opts = array('ftp' => array('overwrite' => true));
$context = stream_context_create($opts);
file_put_contents($file, $contents, NULL, $context);
// the file your trying to get
$file ="http://domain-ONE.com/file.txt";

// get the file USING HTTP
$contents = file_get_contents($file);

// the file your trying to UPLOAD
$file ="ftp://ftp_user:ftp_pass@domain-TWO.com/file.ext";

// write USING FTP
$opts = array('ftp' => array('overwrite' => true));
$context = stream_context_create($opts);
file_put_contents($file, $contents, NULL, $context);
此代码可以在Web服务器上远程运行、在Web服务器上本地运行、在本地使用php cli或在SSH上远程使用php cli


让我知道你的具体要求,我会调整我的答案

你就是不能(否则没用)。您可以上传每个文件。您可以使用Python直接从web服务器将文件写入本地磁盘?我非常怀疑。只需在本地计算机上运行该文件!?该文件位于xxx.yyy.zzz(服务器端),当它进入网络时,让它自动传输到我的本地计算机。你能更清楚地解释一下你的问题吗?