0
我有一些代碼需要使用逗號作爲分隔符的大型文本文件,並將其輸入到數據庫中。從文本文件插入到SQL數據庫中的信息
我收到代碼的fget和feof部分的錯誤。該文件正在成功上傳。
它說:「FEOF():提供的參數是不是一個有效的流資源...」和「與fgets():提供的參數是不是一個有效的流資源......」
if(isset($_POST['submit'])){
$allowedExts = "txt";
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"]/1024) . " kB<br>";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
$tableArray = array();
$handle = @fopen("/uploads/". $_FILES["file"]["name"], "r");
require ('connect.php');
while (!feof($handle)) // Loop til end of file.
{
$buffer = fgets($handle, 4096); // Read a line.
list($fname,$lname,$snumber,$gender,$a , $b, $year,$DOB, $phone,$c,$email,$d,$e,$R,$r,$w)=explode(",",$buffer);
$sql_statement = "INSERT INTO students VALUES ($snumber , $fname , $lname , $gender , $year , $email, $DOB , $phone , 1)";
}
}