2014-02-16 46 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 。

讓我知道你的具體要求,我會調整我的答案

相關問題