如何从mysql数据库中的服务器读取和上传文本文件

时间:2016-04-04 09:03:56

标签: php mysql

我在000webhost服务器上使用网址[http://file_server.comxa.com/remote_server/temp.txt][1]

创建了一个文本文件

我想读取第一个值直到分隔符,这里是代码

<?php
include 'dbconfig.php';
$file = fopen ("http://file_server.comxa.com/remote_server/temp.txt", "r");
if (!$file) {
echo "<p>Unable to open remote file.\n";
exit;
}
while (!feof ($file)) {
$line = fgets ($file, 1024);
if (preg_match ("@\<title\>(.*)\</title\>@i", $line, $out)) {
    $title = $out[1];
    break;
}
$sql = "INSERT INTO `temprature` (`id`, `temprature`) VALUES (NULL, $line)";
$result = mysqli_query($conn,$sql) or die(mysqli_error($conn));
if($result)
{
    echo "temprature inserted";
}
else
{
    echo "failure";
}
}
fclose($file);  
?>

但此代码抛出了错误 Warning: fopen(http://file_server.comxa.com/remote_server/temp.txt): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in C:\xampp\htdocs\demo\server_read.php on line 3 Unable to open remote file.

让我知道我错在哪里

P.S:当我改变我的本地主机文件的路径时,它工作正常

0 个答案:

没有答案