2014-02-16 49 views
-4

有一个免费的ftp空间xxx.yyy.zzz,我用filezilla将代码(名为getweb.php)上传到它。我可以在我的本地磁盘在PHP中的网站?

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

当我inpu XXX.YYY.ZZZ \ getweb.php,我发现有一个在我的FTP空间命名为c:\file.txt文件,我不得不与FileZilla中下载。

我可以做到这一点与python,如何可以将网页直接捕获到我的本地磁盘在PHP代码? ,

+0

你只是不能(或它是无用的)。你很乐意上传每个文件。 – n1xx1

+0

你可以简单地使用Python直接从Web服务器将文件写入本地磁盘?我非常怀疑它。 – deceze

+0

只需在本地机器上运行该文件! – Philipp

回答

0

如果你使用PHP 5中,你可以使用file_put_contents:

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

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

0

代码中使用PHP内置的FTP流

// the file your trying to get 
$file ="ftp://ftp_user:[email protected]/file.txt"; 

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

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

// 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:[email protected]/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:[email protected]/file.txt"; 

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

// the file your trying to UPLOAD 
$file ="ftp://ftp_user:[email protected]/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 ="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:[email protected]/file.ext"; 

// write USING FTP 
$opts = array('ftp' => array('overwrite' => true)); 
$context = stream_context_create($opts); 
file_put_contents($file, $contents, NULL, $context); 

该代码可以远程在网络服务器上的Web服务器在本地使用PHP-CLI或远程使用跑,本地的,PHP-CLI通过SSH 。

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

相关问题