我有两个页面,A页面生成一个.sql的文件并且发送给B页面。B页面负责接收这个文件并保存到本地。目前遇到的问题是A页面如何把这个.sql文件发送到B页面去,并且B页面接收。注:A页面和B页面并不在一台电脑上。我想用soket方法或者其他方法都行。请各位指教。A页面<?php
include_once("post.php");
//此文件放在需要192.168.16.6的服务器,需要读取.6服务器上et数据库表内容
$database='test1';//数据库名
$options[0]="company";
$options[1]="space";
$options[2]="customers";
$options[3]="custorders";mysql_connect("127.0.0.1","root","")or die("不能连接数据库!");
mysql_select_db($database) or die("数据库名称错误!");
mysql_query("SET NAMES utf8");
$date=getdate(time());
$filename="its".$date[year].$date[mon].$date[mday].$date[hours].$date[minutes].$date[seconds].".sql";
$filepath="d:\\SQL\\sqllog\\".$filename;
$fp = fopen($filepath, 'w');for($i=0;$i<sizeof($options);$i++)
{
if($options[$i]!="")
{
dump_table($options[$i], $fp);
}
}//这里如何写把$fp文件发送出去。发送代码!
fclose($fp);
//导出数据库
function dump_table($table, $fp = null)
{
$need_close = false;
if (is_null($fp)) {
$fp = fopen($table . '.sql', 'w');
$need_close = true;
}
$a=mysql_query("show create table `{$table}`");
$row=mysql_fetch_assoc($a);fwrite($fp,$row['Create Table'].';');//导出表结构
$rs = mysql_query("SELECT * FROM `{$table}`");
while ($row = mysql_fetch_row($rs)) {
fwrite($fp, get_insert_sql($table, $row));
}
mysql_free_result($rs);
if ($need_close) {
fclose($fp);
}
}
//导出表数据
function get_insert_sql($table, $row)
{
$sql = "INSERT INTO `{$table}` VALUES (";
$values = array();
foreach ($row as $value) {
$values[] = "'" . mysql_real_escape_string($value) . "'";
}
$sql .= implode(', ', $values) . ");\r\n";
return $sql;
}
?>
<SCRIPT LANGUAGE='JavaScript'>location.href='<?=$url?>';</SCRIPT>
include_once("post.php");
//此文件放在需要192.168.16.6的服务器,需要读取.6服务器上et数据库表内容
$database='test1';//数据库名
$options[0]="company";
$options[1]="space";
$options[2]="customers";
$options[3]="custorders";mysql_connect("127.0.0.1","root","")or die("不能连接数据库!");
mysql_select_db($database) or die("数据库名称错误!");
mysql_query("SET NAMES utf8");
$date=getdate(time());
$filename="its".$date[year].$date[mon].$date[mday].$date[hours].$date[minutes].$date[seconds].".sql";
$filepath="d:\\SQL\\sqllog\\".$filename;
$fp = fopen($filepath, 'w');for($i=0;$i<sizeof($options);$i++)
{
if($options[$i]!="")
{
dump_table($options[$i], $fp);
}
}//这里如何写把$fp文件发送出去。发送代码!
fclose($fp);
//导出数据库
function dump_table($table, $fp = null)
{
$need_close = false;
if (is_null($fp)) {
$fp = fopen($table . '.sql', 'w');
$need_close = true;
}
$a=mysql_query("show create table `{$table}`");
$row=mysql_fetch_assoc($a);fwrite($fp,$row['Create Table'].';');//导出表结构
$rs = mysql_query("SELECT * FROM `{$table}`");
while ($row = mysql_fetch_row($rs)) {
fwrite($fp, get_insert_sql($table, $row));
}
mysql_free_result($rs);
if ($need_close) {
fclose($fp);
}
}
//导出表数据
function get_insert_sql($table, $row)
{
$sql = "INSERT INTO `{$table}` VALUES (";
$values = array();
foreach ($row as $value) {
$values[] = "'" . mysql_real_escape_string($value) . "'";
}
$sql .= implode(', ', $values) . ");\r\n";
return $sql;
}
?>
<SCRIPT LANGUAGE='JavaScript'>location.href='<?=$url?>';</SCRIPT>
http://dtbaker.com.au/random-bits/uploading-a-file-using-curl-in-php.html
理解成有a,b两服务器!a服务器生成.sql类型的数据,然后发送到b服务器并接收!解决方式:
b服务器做个webservice,接收a服务器发送过来的数据!
方法:
1.curl
2.socket
3.file_get_contents三种方式均可,具体使用你到google上搜下一大把!
希望对你有所帮助!