作者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
1F:推 Fantasywind:$_POST['file']? 传档应该用 $_FILES 08/22 12:01
2F:→ Fantasywind:$_POST['file']里面是存什麽 贴个form上来看看 08/22 12:03
from在文章最上面 帮我看了 拜托
※ 编辑: sing10407 来自: 1.34.148.102 (08/22 12:05)
3F:→ 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)
4F:→ kerash:我回太晚了,我指的是 $_FILES["file"]["filename"] 08/22 15:53
5F:→ kerash:或者 tmp_name 08/22 15:53
没关系,感谢你的解答!
※ 编辑: sing10407 来自: 1.34.148.102 (08/22 16:20)
6F:→ iceblue7x:from 传档案要加 enctype="multipart/form-data" 08/22 23:10
Thanks !!
※ 编辑: sing10407 来自: 1.34.148.102 (08/23 10:12)