我使用PHPExcelReader来解析excel文件(由用户从本地机器选择)。PHP将获取这些值并将其存储在数组中,然后重新组织并以表的形式显示在屏幕上。
然而,在我浏览文件后,一旦我点击"提交",我得到错误:File not found
下面是HTML:
<div class="row-fluid" style="margin-top:15px">
<h2>Step 1: Import the file</h2>
<p>Once uploaded, the window will display a preview of the document. Please check to make sure the column
headers match the data before uploading.</p>
<form action="../scripts/previewFile.php" method="post" enctype="multipart/form-data">
<input type="file" name="fileToUpload" />
<input type="submit" value="Preview File" name="submit">
<div id="filePreview" style="height: 500px; overflow: scroll;">
</div>
</form>
</div>
被调用的previewFile.php文件:
function previewFile()
{
$filePath = $_FILES['file']['tmp_name'];
$excel = new Spreadsheet_Excel_Reader; // creates object instance of the class
$excel->read($filePath);
}
这个错误是一个404的PHP文件"previewFile.php"被调用作为一个动作。
不知道我的URL "../scripts/previewFile.php"
有什么问题
这是我的schema:
root
|_views
|_default
|_assets
|_scripts
|_previewFile.php
|_templates
|_step1.php <- the html file with the input tags
您的输入名称是fileToUpload
,并且您正在$_FILES
数组中查找file
,因此它应该如下所示:
function previewFile()
{
$filePath = $_FILES['fileToUpload']['tmp_name'];
$excel = new Spreadsheet_Excel_Reader; // creates object instance of the class
$excel->read($filePath);
}