首页 > 解决方案 > 不幸的是 PHP file_get_contents 不工作

问题描述

我正在尝试获取存储在数据库中的 url。我可以回显 url 但是当我尝试使用 file_get_contents 函数来获取页面时,它说failed to open stream: No such file or directory

用于从数据库中获取数据的 PHP 代码

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT Job, Link FROM primarydata";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
// output data of each row
 while($row = $result->fetch_assoc()) {
    $job = $row["Job"];
    $link = $row["Link"];       
    echo $job;
    echo $link;
    $htmlcontent =  file_get_contents($link);
    echo $htmlcontent;
 }
} else {
echo "0 results";
}
$conn->close();
?> 

我能够回显 URL,但在下一个链接中它不执行该file_get_contents功能

标签: phpmysql

解决方案


推荐阅读