作者sing10407 (阿U)
看板PHP
標題[請益]The filename bb.xls is not readable
時間Wed Aug 22 11:50:04 2012
我的問題是這樣的
目前我想要做一個可以上傳.xls檔然後依照欄位寫進資料庫
我在localhost時還可以
但是放到虛擬主機後卻發生
the filename bb.xls is not readable 這種問題
請問是哪裡出錯呢?
我的code如下
<form id="form1" name="form1" method="post" action="">
<label>
<input name="file" type="file" id="file13"/>
<input type="submit" name="Submit" value="提交" />
</label>
</form>
<?php
include_once 'MYSQL.php';
require_once 'reader.php';
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('utf-8');
if(isset($_POST['Submit'])){
$data->read($_POST['file']); //這一行是read
for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
$sql = "INSERT INTO excel_input (ex_account,ex_pw,ex_type)
VALUES('".$data->sheets[0]['cells'][$i][1]."','".$data->sheets[0]['cells'][$i][2]."','".$data->sheets[0]['cells'][$i][3]."')";
$query=mysql_query($sql);
if($query){
echo '<script language="javascript">window.alert("讀取成功
!");</script>';
header('Location:total.php');
}else{
echo '<script language="javascript">window.alert("讀取失敗
!");</script>';
header('Location:total.php');
}
}
}
?>
在localhost可以成功讀取成功寫進資料庫
換到虛擬主機就不行了 有人知道為什麼嗎?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 1.34.148.102
推 Fantasywind:$_POST['file']? 傳檔應該用 $_FILES 08/22 12:01
→ Fantasywind:$_POST['file']裡面是存什麼 貼個form上來看看 08/22 12:03
from在文章最上面 幫我看了 拜託
※ 編輯: sing10407 來自: 1.34.148.102 (08/22 12:05)
→ kerash:用 $_FILE 讀 name 08/22 12:10
$data->read($_FILES['file']); 這樣也是沒辦法
原本是想說用$_POST['file']; 直接讀post的檔案就好了
還是要先存起來再讀取呢?
※ 編輯: sing10407 來自: 1.34.148.102 (08/22 12:16)
已解決,最後我把它先上傳到伺服器成功後再讀取即可
感謝各位大大
※ 編輯: sing10407 來自: 1.34.148.102 (08/22 13:00)
→ kerash:我回太晚了,我指的是 $_FILES["file"]["filename"] 08/22 15:53
→ kerash:或者 tmp_name 08/22 15:53
沒關係,感謝你的解答!
※ 編輯: sing10407 來自: 1.34.148.102 (08/22 16:20)
→ iceblue7x:from 傳檔案要加 enctype="multipart/form-data" 08/22 23:10
Thanks !!
※ 編輯: sing10407 來自: 1.34.148.102 (08/23 10:12)