Ⅰ 用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;
}
?>