【问题标题】:Importing a text file into an array with a button (PHP/HTML)使用按钮将文本文件导入数组 (PHP/HTML)
【发布时间】:2019-05-22 20:07:56
【问题描述】:

我想要从我的电脑中选择并打开一个 .txt 文件到一个数组中。我可以很容易地做到这一点;

$arr = explode("\n", file_get_contents('sampledata.txt'));

但我想用一个按钮来做。

<input type="file" name="my_file">

我可以使用该按钮选择文件,但我不知道如何创建数组。我将使用文本文件 ($arr) 中的数字进行 php 计算。这是可能的还是我在做梦?

谢谢。

【问题讨论】:

标签: php html button


【解决方案1】:

上传的文件信息在$_FILES['my_file']。你可以这样做:

if (isset($_FILES['my_file'])) {
    $arr = file($_FILES['my_file']['tmp_name'], FILE_IGNORE_NEW_LINE);
    // ... do stuff with $arr
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-08
    • 2013-05-16
    • 2017-09-29
    • 2012-08-31
    • 1970-01-01
    • 2021-12-06
    • 2015-07-08
    相关资源
    最近更新 更多