导航:首页 > 编程语言 > php调用远程文件

php调用远程文件

发布时间:2022-08-26 13:17:23

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程序自动读取远程文件并更新到本地,每天一次,如何做

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远程读取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读取远程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;
}
?>

⑸ php怎样遍历远程文件夹下的文件

window是用的GB2312的编码,你的php文件应该用的是UTF-8,所以正如你写的那样,先要转换编码$dir=iconv("utf-8","gb2312",$dir);
但你别忘了,你用的是UTF-8的编码,所以你第六行写错了,把GB2312转换为UTF-8搞倒了吧
123456789101112131415<?phpfunction refresh($dir){ $dir=iconv("utf-8","gb2312",$dir); if ($headle=opendir($dir)){ while ($file=readdir($headle)){ $file=iconv("gb2312","utf-8",$file); if ($file!='.' && $file!='..'){ echo "文件".$file."在文件夹".$dir."下<br />"; } } closedir($headle); }}refresh("D:/AppServ/www/test");?>

⑹ 怎么用php获取远程xml到本地

<?php
$xml_string = file_get_contents("php://input");
$xml_string = trim($xml_string);
$xml_object = simplexml_load_string($xml_string);
$xml_arr = get_object_vars($xml_object);
只要别人访问你这个文件传递xml。你就能获取其中的信息了。

⑺ PHP远程文件调用问题

用PHP的CURL 函数吧。

⑻ 请问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 网络开发详解之远程文件包含漏洞

以下代码(Code)实现了根据浏览器地址栏参数的文件名称包含不同文件的功能。
复制代码
代码如下:
<?php
$file_name
=
$_GET["filename"];
//获得当前文件名
include("$file_name
");
//包含文件
//一些其他操作
?>
这时,通过在地址栏上指定不同的文件名就可以实现包含不同文件并执行的功能。例如,通过在浏览器上访问http://localhost/test.php?filename=myinc.php就可以在代码(Code)中包含并执行myinc.php文件。
由于上面的代码(Code)没有进行任何错误处理,在浏览器上不加参数运行,所以将得到以下运行结果。
Warning:
include(.php)
[function.include]:
failed
to
open
stream:
No
such
file
or
directory
in
C:\Program
Files\xampp\htdocs\Bugs\test6.php
on
line
3
Warning:
include()
[function.include]:
Failed
opening
'.php'
for
inclusion
(include_path='.;C:\Program
Files\xampp\php\pear\')
in
C:\Program
Files\xampp\htdocs\Bugs\test6.php
on
line
3
访问者通过读取这段错误信息,可以得知当前的操作是一个文件包含操作。这时,可以在自己的服务器上放置一个相应的脚本代码。需要注意的是PHP在获取远程文件时获得的是远程服务器的最终输出结果,而不是文件本身。该脚本代码位于192.168.0.1服务器上,文件名为hello.txt,脚本代码(Code)如下所示。
复制代码
代码如下:
<?php
echo
"hello
world!";
?>
这时,通过在浏览器中访问http://localhost/test.php?filename=http://192.168.0.1/hello.txt就可以运行hello.txt中的脚本了。
为了解决这个问题,一种方式是完善代码的错误信息,使访问者无法知道当前脚本正在包含参数中指定的文件。修改后的代码(Code)如下所示。
复制代码
代码如下:
<?php
$file_name
=
$_GET["filename"];
//获得当前文件名
if(!@include("$file_name.php"))
//包含文件
{
die("页面在浏览过程中出现错误");
}
//一些其他操作
?>
修改后,如果在被包含的文件无法找到时将出现“页面在浏览过程中出现错误”的错误信息,访问者将无法获得当前页面的具体操作信息。
第二种方式可以更加有效地防止远程文件包含攻击。方式是替换地址栏参数中的斜线“/”。这样,在地址栏参数中输入远程文件地址时,代码将无法正确地获得参数。修改后的代码(Code)如下所示。
复制代码
代码如下:
<?php
$file_name
=
str_replace('/',
'',
$_GET["filename"]);
//获得当前文件名
if(!@include("$file_name.php"))
//包含文件
{
die("页面在浏览过程中出现错误");
}
//一些其他操作
?>
这样,在浏览器中访问http://localhost/test.php?filename=http://192.168.0.1/hello.txt
时,实际上PHP代码(Code)获得的包含文件名称是http:192.168.0.1bugstest6_test。页面将不会包含远程文件,并显示相应的错误信息。

阅读全文

与php调用远程文件相关的资料

热点内容
愿望清单app哪个好 浏览:457
安卓外放声音怎么解决 浏览:194
脉脉app干什么用的 浏览:357
拽姐是哪个app 浏览:858
云服务器删除了还有吗 浏览:232
macbook可以用单片机嘛 浏览:307
南阳php招聘 浏览:814
去哪里找按摩师很漂亮的app 浏览:818
86x99用简便算法计算 浏览:830
php截图flash 浏览:274
卸载联想app哪个好 浏览:721
php文字转图片 浏览:332
豆客后台怎么加密码 浏览:575
jpg转换pdf破解版 浏览:979
php基础书籍推荐 浏览:779
服务器与外网不通如何验证 浏览:353
电子版是不是就是文件夹 浏览:52
游戏属性文件加密 浏览:464
如何让安卓手机桌面图标下移 浏览:530
ubuntuphp5环境搭建 浏览:101