2016-05-15 96 views
1

我想從另一個目錄中導入PHP中的excel文件。我想讀Excel和顯示其內容,但其在另一個diretory,我得到一個錯誤從另一個目錄導入並顯示PHP中的excel文件。我想讀取excel並顯示其內容

Notice: Undefined index: file in F:\Xampp\htdocs\upload.php on line 3 

import.php

<form action="upload.php" > 
<input name="file" type="file"> 
<input name="submit" type="submit"> 
</form> 

upload.php的

<?php 
$uploadedStatus = 0; 
echo $_FILES["file"]["name"]; 
?> 

回答

0

確保您的表單具有用於處理文件上傳的enctype屬性。

<form action="upload.php" enctype="multipart/form-data"> 
    <input name="file" type="file"> 
    <input name="submit" type="submit"> 
</form> 

參考文獻:

  1. Importing excel files using PHP
  2. PHP Excel reader
1

對於顯示的Excel在PHP中您可以使用PHPExcel這樣的:

include 'PHPExcel/IOFactory.php'; 
$inputFileType = 'Excel5'; 
$inputFileName = 'MyExcelFile.xls'; 

$objReader = PHPExcel_IOFactory::createReader($inputFileType); 
$objPHPExcel = $objReader->load($inputFileName); 

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML'); 
$objWriter->save('php://output'); 
exit; 

上傳你可以使用simple file upload這樣的文件:

PHP 「upload.php的」:

<?php 
     $target_dir = "uploads/"; 
     $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); 
     $uploadOk = 1; 
     $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); 
     if(isset($_POST["submit"])) { 
      if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { 
       echo "The file ". basename($_FILES["fileToUpload"]["name"]). " has been uploaded."; 
      } else { 
       echo "Sorry, there was an error uploading your file."; 
       } 
     } 
    ?> 

HTML表單:

<!DOCTYPE html> 
<html> 
<body> 

<form action="upload.php" method="post" enctype="multipart/form-data"> 
    Select image to upload: 
    <input type="file" name="fileToUpload" id="fileToUpload"> 
    <input type="submit" value="Upload Image" name="submit"> 
</form> 

</body> 
</html> 
相關問題