我有一个脚本,除了.txt文件与输入文件完美地工作。我真的不知道它有什么问题。但如果我打开其他扩展(如.csv、.rar、.zip等),它就可以工作了,而且我的$_POST上也有一些东西。但是如果我使用任何*.txt文件,我只会在我的$_POST上得到数组空。
如果我使用以下代码:
$sListText = file_get_contents("act20170713.txt");
echo "<br/>".nl2br($sListText);它就是完美的工作。但是如果我使用:
$fileexcel = $_FILES['txt']['tmp_name'];
echo $fileexcel;我得到一个只有*.txt文件的数组null
有没有人能给我解释一下,或者有解决方案?任何答案都将不胜感激。提前感谢。
亲切的问候,Fondra
我为更详细的enter image description here添加了一些屏幕截图
完整代码:
<form action="" method="post" enctype="multipart/form-data" name="form2" id="form2">
<div class="row">
<div class="col-md-3">
<input id="file" type="file" name="txt" style="text-align:right;-moz-opacity:0;filter:alpha(opacity:0);opacity:1;z-index: 2;"/>
</div>
<div class="col-md-3" style="padding-left:4.5%"><input type="submit" name="list" class="btn btn-info" value="Show"/></div>
<div class="col-md-3"></div>
<div class="col-md-3" ><input type="submit" name="clear" class="btn btn-default" value="Clear" style="float:right"/></div>
</div>
</form>
<?php if (isset($_POST['list'])){
var_dump($_FILES);
$fileexcel = $_FILES['txt']['tmp_name'];
echo $fileexcel;
print_r($_FILES['txt']);
//echo "test";
//$sListText = file_get_contents("act20170713.txt");
//$data = explode("\n", $sListText);
?}发布于 2017-07-18 11:03:08
txt文件很大吗?也许PHP被文件大小卡住了?检查upload_max_filesize和post_max_size的php配置设置-我见过文件超出post_max_size没有返回任何错误的情况,类似于你的情况。
发布于 2017-07-18 10:01:25
我想你可以通过var_dump($_FILEs)来查看,并检查你的html表单是不是有enctype="multipart/form-data"
发布于 2017-07-18 10:00:25
这是关于如何读取我在W3Schools上找到的文本文件的PHP5。
<?php
$myfile = fopen("webdictionary.txt", "r") or die("Unable to open file!");
echo fread($myfile,filesize("webdictionary.txt"));
fclose($myfile);
?> 希望这能有所帮助。
https://stackoverflow.com/questions/45156218
复制相似问题