我需要创建一个脚本来读取文件并发布数据,以便可以在另一台机器上接收。
有没有人对我从哪里开始有任何想法? PHP.Net上唯一看起来类似的东西就是使用dir("/etc/php5
答案 0 :(得分:1)
使用PHP,您可以使用libcurl
将文件上传到远程服务器。你不需要做任何特殊的事情来阅读文件,只需给出卷曲的路径。以下是发送文件的示例:
$target_url = 'http://127.0.0.1/accept.php';
//This needs to be the full path to the file you want to send.
$file_name_with_full_path = realpath('./sample.jpeg');
/* curl will accept an array here too.
* Many examples I found showed a url-encoded string instead.
* Take note that the 'key' in the array will be the key that shows up in the
* $_FILES array of the accept script. and the at sign '@' is required before the
* file name.
*/
$post = array('extra_info' => '123456','file_contents'=>'@'.$file_name_with_full_path);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result=curl_exec ($ch);
curl_close ($ch);
echo $result;
此代码来自Derak,有关所有详细信息,请参阅http://blog.derakkilgo.com/2009/06/07/send-a-file-via-post-with-curl-and-php/。
请注意,您根本不需要PHP,you can simply use curl
from the command line或shell脚本。
答案 1 :(得分:0)
使用XML PHP函数将数据解析为转储文件,然后在另一台机器上使用不同的函数读取它。