gpt4 book ai didi

php - 无法上传 csv 文件并出现错误 C :\xampp\tmp\php9F4F. tmp

转载 作者:行者123 更新时间:2023-11-29 17:47:30 35 4
gpt4 key购买 nike

我正在开发一个网站,该网站要求我创建上传 .csv 文件的函数。上传文件时,提示格式错误,并显示以下消息:

C:\xampp\tmp\php9F4F.tmp

我应该如何解决该错误,然后将 csv 文件上传到我的数据库中?

stdreport.php ://im 使用 import.php 中的相同代码将其与数据库连接

<?php
$SQLSELECT = "SELECT stdCard, stdName, stdProgram, stdCourseDesc, stdCampus
FROM student
ORDER BY stdID
LIMIT 0,20";

$result_set = mysql_query($SQLSELECT, $conn);
while($row = mysql_fetch_array($result_set))
{
?>

导入.php

<?php 
$conn=mysql_connect("localhost","root","") or die("Could not connect");
mysql_select_db("dashboard",$conn) or die("could not connect database");

if(isset($_POST["Import"])){

echo $filename=$_FILES["file"]["tmp_name"];

if($_FILES["file"]["size"] > 0) {

$file = fopen($filename, "r");
while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE) {

//It wiil insert a row to our subject table from our csv file`
$sql = "INSERT into student
(`stdID`, `stdCard`, `stdName`,
`stdOfficialEmail`,`stdEmail`,
`stdContNum`,`stdCourseDesc`, `stdCampus`,
`accessDate`)
values('$emapData[1]','$emapData[2]','$emapData[3]',
'$emapData[4]','$emapData[5]',
'$emapData[6]', '$emapData[7]','$emapData[8]',
'$emapData[9]')";

//we are using mysql_query function. it returns a resource on true else False on error
$result = mysql_query( $sql, $conn );
if(! $result ) {
echo "<script type=\"text/javascript\">
alert(\"Invalid File:Please Upload CSV File.\");
window.location = \"stdreport.php\"
</script>";
}
}
fclose($file);
//throws a message if data successfully imported to mysql database from excel file
echo "<script type=\"text/javascript\">
alert(\"CSV File has been successfully Imported.\");
window.location = \"stdreport.php\"
</script>";

//close of connection
mysql_close($conn);
}
}
?>

最佳答案

当您将 Excel 文件转换为 CSV 时,有两种类型的 formate CSV UTF-8(逗号分隔),第二种是 CSV(逗号分隔),请使用第二个选项,我还附上了屏幕截图。

enter image description here

关于php - 无法上传 csv 文件并出现错误 C :\xampp\tmp\php9F4F. tmp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49687641/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com