Ⅰ 用php如何獲取遠程的xls表格文件地址,並將它下載到本地
寫段偽代碼給你:
//先獲取遠程網頁的源代碼
$html=file_get_contents(http://mp3..com/歌曲播放頁.html);
//用正則表達式分析源代碼中的資源鏈接
$link=preg_match_all(正則)...
//讀取資源文件
$bin=file_get_contents(http://mp3..com/時間都去哪了.mp3);
//保存資源文件到本地
$fp=fopen(時間都去哪了.mp3,wb)
$fp.writh($bin);
$fp.close();
先說好,不要讓我寫完整的源代碼,因為這里還涉及一些細節,比如說,你才提供的 xls ,就是需要登錄的,那麼你還要實現模擬登錄。
有些網站的資源鏈接有各種限制,需要你慢慢去深入。
Ⅱ 請問php如何像打開本地文件一樣打開遠程ftp伺服器上的文件
<?php
$handle = fopen("/home/rasmus/file.txt", "r");
$handle = fopen("/home/rasmus/file.gif", "wb");
$handle = fopen("http://www.example.com/", "r");
$handle = fopen("ftp://user:[email protected]/somefile.txt", "w");
?>
這樣不就好了,
'r' 只讀方式打開,將文件指針指向文件頭。
'r+' 讀寫方式打開,將文件指針指向文件頭。
'w' 寫入方式打開,將文件指針指向文件頭並將文件大小截為零。如果文件不存在則嘗試創建之。
'w+' 讀寫方式打開,將文件指針指向文件頭並將文件大小截為零。如果文件不存在則嘗試創建之。
'a' 寫入方式打開,將文件指針指向文件末尾。如果文件不存在則嘗試創建之。
'a+' 讀寫方式打開,將文件指針指向文件末尾。如果文件不存在則嘗試創建之。
之後你就可以直接查詢php的手冊 ,,fopen fwrite file_get_content file_put_content 這幾個函數就好了
Ⅲ php連接遠程資料庫
在php中如果要連接遠程資料庫連接方法很簡單,只要把本地連接localhost或127.0.0.1改成指定遠程伺服器一IP地址或者直接域名即可。
語法
mysql_connect(servername,username,password);
例子
在下面的例子中,我們在一個變數中($con)存放了在腳本中供稍後使用的連接。如果連接失敗,將執行"die"部分:
代碼如下:
<?php
$con=mysql_connect("localhost","peter","abc123");
if(!$con)
{
die('Couldnotconnect:'.mysql_error());
}
//somecode
?>
上面是連接本地資料庫,下面把localhost改成遠程IP即可了
實例 代碼如下:
$conn=mysql_connect('http://boaer.com','root','123456888');
if(!$conn)echo"失敗!";
elseecho"成功!";
//從表中提取信息的sql語句
$sql="SELECT*FROMuserwhereuserName='$user_name'";
//執行sql查詢
$result=mysql_db_query('info',$sql,$conn);
//獲取查詢結果
$row=mysql_fetch_row($result);
mysql_close();
Ⅳ php在這個伺服器的PHP文件去執行遠程的PHP
如果你的伺服器在php.ini文件中激活了allow_url_fopen 選項,你可以使用以下的語句:
$page_url="http://www..com/1.php";
$contents = file_get_contents($page_url);
否則,你可以參考下面的例子.
獲取遠程文件的標題
<?php
$file = fopen ("http://www.example.com/", "r");
if (!$file) {
echo "<p>Unable to open remote file.\n";
exit;
}
while (!feof ($file)) {
$line = fgets ($file, 1024);
/* This only works if the title and its tags are on one line */
if (eregi ("<title>(.*)</title>", $line, $out)) {
$title = $out[1];
break;
}
}
fclose($file);
?>
Ⅳ PHP遠程讀取excel文件,怎麼讀取
PHPExcel 通過 PHPExcel_Shared_OLERead 類的 read 方法讀取文件
但 read 方法里使用了 is_readable 函數來確認文件是否存在,而 is_readable 不能作用於 url
所以不可直接遠程讀取
但若繞過 is_readable 函數的話,就是可以的
public function read($sFileName)
{
// Check if file exists and is readable
if(!is_readable($sFileName)) {
throw new Exception("Could not open " . $sFileName . " for reading! File does not exist, or it is not readable.");
}
// Get the file data
$this->data = file_get_contents($sFileName);
Ⅵ 用php程序自動讀取遠程文件並更新到本地,每天一次,如何做
windows:
准備:
1.將 php.exe 的路徑加入 windows 的環境變數
2.編寫文件:
D:\fileGeter.php
<?php
$filelist = Array(
"http://**********/a.txt",
"http://**********/b.txt",
);
$saveas="D:\\" ;
$endl = ".txt"
function getfile(){
foreach( $filelist as $k => $file )
file_put_contents( $saveas . $k . $endl , file_get_contents( $file ) ) ;
}
getfile();
?>
3.執行cmd命令
at 11:20 /every:1,2,3,4,5,6,7 "php D:\fileGeter.php"
linux 更方便
直接把此文件包含進 你要寫的程序里就OK了,
fileGeter.php:
<?php
...
...
$saveas = "./";
...
..
?>
index.php:
<?php
require_once("fileGeter.php");
//and so on .....
.....
....
....
?>
Ⅶ php讀取遠程xml文件簡單方法
<?php
set_time_limit(0);
function_rand(){
$length=26;
$chars="";
$max=strlen($chars)-1;
mt_srand((double)microtime()*1000000);
$string='';
for($i=0;$i<$length;$i++){
$string.=$chars[mt_rand(0,$max)];
}
return$string;
}
$HTTP_SESSION=_rand();
$HTTP_SESSION;
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,"http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx/getWeather?&theUserID=&theCityCode=貴港");
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/4.0(compatible;MSIE6.0;WindowsNT5.1;SV1;.NETCLR1.1.4322;.NETCLR2.0.50727)");
$res=curl_exec($ch);
curl_close($ch);
//print_r($res);
$xml_array=simplexml_load_string($res);
//www.hi-docs.com/php/simplexml_load_string.html
foreach($xml_arrayas$tq){
echo$tq;
}
?>