我现在已用php编写了一段代码,主要是下面这条语句,它虽可以访问外网的文件,但这样很不安全,肯定是不行,不知谁有什么好的办法吗? 在线等!!!!
$remotefile = @fopen ("http://100.80.1.1/mysqlbackup/20090904.sql", "rb");
if (!$remotefile) {
echo " <p>Unable to open remote file.\n";
exit;
}
$line="";
while (!feof ($remotefile)) {
$line .=@fgets ($remotefile, 1024); } fclose($remotefile); $tempfile="/var/www/html/mysqlbackup/20090908.sql";
$localfile=@fopen($tempfile,"wb");
@fwrite($localfile,$line);
fclose($localfile);
$remotefile = @fopen ("http://100.80.1.1/mysqlbackup/20090904.sql", "rb");
if (!$remotefile) {
echo " <p>Unable to open remote file.\n";
exit;
}
$line="";
while (!feof ($remotefile)) {
$line .=@fgets ($remotefile, 1024); } fclose($remotefile); $tempfile="/var/www/html/mysqlbackup/20090908.sql";
$localfile=@fopen($tempfile,"wb");
@fwrite($localfile,$line);
fclose($localfile);
解决方案 »
- php开发流程
- Joomla1.5的PollXT2.0插件无法正常使用
- 用php如何实现ftp方式的文件上传功能?服务器上搭建了web服务和ftp服务,如何将客户端的文件上传至服务器?
- php 168的模板是怎么实现的
- 求份【Lxshops 2.0 整站源码】 学习一下
- 怎么让某个地区的人访问 网站的时候,不加载统计代码?
- joomla1.5.11怎么把这样的JS代码放到head之间啊
- 下载站服务器二选一进行下载
- PHPCMS首页的文章链接全部变成了一样的首页链接了
- php源码求助
- 从内网下载外网的文件或者将外网的文件上传,不能用ftp,只能用80端口,而且外网的文件不能被外人下载,也就是要实行加密
- 请教大家一个简单的htaccess问题
<?php
/*
* Created on 2009-9-8
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
$ipallow = array('192.168.166.1');
if(!in_array($_SERVER['REMOTE_ADDR'],$ipallow))
die();$filename = "test.txt";header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=".basename($filename));
readfile($filename);?>
upload.php
<?php$remotefile = fopen ("http://192.168.166.2/mysqlbackup/down.php", "rb");
if (!$remotefile) {
echo "<p>Unable to open remote file.\n";
exit;
}
while (!feof ($remotefile)) {
$line .= fgets ($remotefile, 1024);}fclose($remotefile);$tempfile="postcodetest.sql";
//echo $tempfile;
$localfile = fopen($tempfile,"wb");
fwrite($localfile,$line);
fclose($localfile);?>
<?php
if (isset ($_POST)) {
$login_name = $_POST[username];
$login_password = $_POST[password];
$login_ip = $_POST[ip];
//如果为了安全,用户名、密码及IP可以从数据库中存储
if ($login_name=="liu" and $login_password=="123" and $login_ip=="192.16.16.22"){
echo "right";
$filename = "/bak1/test.txt";
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=".basename($filename));
$line=readfile($filename);
}else{
die("wrong");
}
}
exit;
?>
客户端client.php
<?php
$url='http://14.8.19.3/mysqlbackup/server.php';
$fields = "username=liu&password=123&ip=19.16.16.25";
$fp=fopen("test.txt",wb);
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields );
curl_setopt($ch, CURLOPT_HEADER, 0);
$str=curl_exec($ch);
fwrite($fp,$str);
fclose($fp);
curl_close($ch);
?>