我的脚本没有读取* .txt文件

时间:2012-12-02 17:00:18

标签: php

我有一个带有两个值的表单。一个是.txt文件,一些链接是硬编码的文件和一个带URL的文本字段。当我按下提交时,它会获取该URL并检查* .txt文件中的每个链接。希望你明白我的意思,如果没有那么请评论我会澄清它。现在我有问题了。在链接所在的文件不在我的服务器上之前,我的代码不起作用。我不知道如何处理这个问题。我已经完成了我的搜索,我也尝试了mysql,但这对我来说不行。我的脚本是这样的:

Enter your file :<input type="file" name="ufile" />
Enter your site name :<input type="text" name="utext" />
<input type="submit" value="Check" />

现在,我的php脚本是这样的:

$needle = $_POST['utext'];
$file = $_FILES['ufile'];
$new = file($file, FILE_IGNORE_EMPTY_LINES | FILE_SKIP_EMPTY_LINES);
$new = array_map('trim', $new);
echo 'Total entries are: '.count($new).'<br />';
$found = array();
$notfound = array();
foreach ($new as $check) {
    echo "<table border='1'><tr>";
    echo "<td>Processing</td> <td>", $check,"</td></tr>";
    $a = file_get_contents($check);
    if (strpos($a, $needle)) {
        echo "<td><font color='green'>Found:</font></td>";
        $found[] = $check;
    } else {
        echo "<td><font color='red'>Not Found</font></td>";
        $notfound[] = $check;
    }
    echo "</tr></table>";
}
echo "Matches ".count($found)."<br />";
echo "Not Matched ".count($notfound);

1 个答案:

答案 0 :(得分:2)

你有没有理由read the documentation about how PHP首先处理上传?这表明$_FILES['ufile'] 数组,因此您的代码无法正常工作。如果你真的想在不理解代码的情况下继续编写代码,那么请替换:

$file = $_FILES['ufile'];

$file = $_FILES['ufile']['tmp_name'];
相关问题