我可以读取本地主机的csv文件,一旦我转移到在线显示错误 警告:fopen(boo1.csv):无法打开流:第28行/home/ashishco/public_html/group/fetchCsv.php中没有此类文件或目录,
我不知道如何给出路径。
<?php
include("includes/connection.php");
include("includes/mail.php");
if(isset($_POST["Import"]))
{
echo $filename=$_FILES["file"]["name"];
//echo $ext=substr($filename,strrpos($filename,"."),(strlen($filename)-strrpos($filename,".")));
mysql_query("CREATE TABLE IF NOT EXISTS mytable (
`MId` bigint(20) NOT NULL AUTO_INCREMENT,
`Batch` varchar(50) NOT NULL,
`Department` varchar(50) NOT NULL,
`RegisterNo` varchar(50) NOT NULL,
`Name` varchar(200) NOT NULL,
`EmailId` varchar(250) NOT NULL,
`Password` varchar(50) NOT NULL,
`MobileNo` int(50) NOT NULL,
`Status` tinyint(4) NOT NULL DEFAULT '0',
PRIMARY KEY (`MId`)
)");
if($_FILES["file"]["size"] > 0)
{
$file = fopen($filename, "r");
$count=1;
while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
{
//print_r($emapData);
if($count>1)
{
$sql = "INSERT into myTable(Batch,Department,RegisterNo,Name,EmailId,Password,MobileNo) values('$emapData[0]','$emapData[1]','$emapData[2]','$emapData[3]','$emapData[4]','$emapData[5]','$emapData[6]')";
//echo $sql;
mysql_query($sql);
}
$count++;
}
//die();
fclose($file);
echo "CSV File has been successfully Imported";
fnSendMail();
}
else
{
echo "Invalid File:Please Upload CSV File";
}
}
?>
答案 0 :(得分:0)
你应该像这样给出你的道路
$file = fopen("/ your path/".$filename, "r");
假设您的csv文件的路径为/home/group/file.csv,而您的php文件的路径为/home/yourphp.php,那么您将调用
$file = fopen("/group/".$filename, "r");
在你的情况下只是用作
$file = fopen($filename, "r");