2013-07-16 4 views
0

나는 PHP를 처음 사용했습니다. 나는 mysql에 파일을 엑셀로 가져 오기 위해 노력했다. 하지만 난 wamp/www/samp.xls에서 Excel 파일 만 가져옵니다. D : 또는 E :와 같은 다른 위치에서 Excel 파일을 가져와야합니다. 그것을 얻을 수있는 방법, 나에게 해결책을 줘./samp.xls는 WAMP/www가있다 위치에 대한 내 코드입니다 :가져 오기 다른 위치에서 파일을 엑셀 및 PHP에서 MySQL에 저장

<html> 
    <head> 
    <title>Save Excel file details to the database</title> 
    </head> 
    <body>`enter code here` 
    <?php 
     include 'db_connection.php'; 
     include 'reader.php'; 
     $excel = new Spreadsheet_Excel_Reader(); 
    ?> 
     <table border="1"> 
     <?php 
      $excel->read('samp.xls'); 
      $x=2; 
      while($x<=$excel->sheets[0]['numRows']) { 
       $id = isset($excel->sheets[0]['cells'][$x][1]) ? $excel->sheets[0]['cells'][$x][1] : ''; 
       $name = isset($excel->sheets[0]['cells'][$x][2]) ? $excel->sheets[0]['cells'][$x][2] : ''; 
       $age = isset($excel->sheets[0]['cells'][$x][1]) ? $excel->sheets[0]['cells'][$x][3] : ''; 
       $email = isset($excel->sheets[0]['cells'][$x][2]) ? $excel->sheets[0]['cells'][$x][4] : ''; 
       // Save details 
       $sql_insert="INSERT INTO students (sid,name,age,email) VALUES ('$id','$name','$age','$email')"; 
       $result_insert = mysql_query($sql_insert) or die(mysql_error()); 
       $x++; 
      } 
     ?> 
    </table> 
    </body> 
</html> 
+0

사용 a를 다음과 같이 PHP 측에서 양식을 처리 양식을 업로드하려면 – DevZer0

+0

나는 PHP를 처음 사용했습니다. 몇 가지 예를 들어 – Kalai

+0

시도 http://phpexcel.codeplex.com/ –

답변

0

이 기본 형태를

<form enctype='multipart/form-data'><input type="file" name="excel" /> <input type="submit" value="upload" /></form> 

를 사용하고

$excel->read($_FILES['excel']['tmp_name']);