gpt4 book ai didi

php - 使用fgetcsv时PHP返回错误

转载 作者:可可西里 更新时间:2023-11-01 00:26:58 26 4
gpt4 key购买 nike

可能重复:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select
嗨,我正在尝试用fgetcsv处理csv,但我要做的只是无限循环的错误
警告:第5行testcsv.php中的fopen(“tile”,“user”…)
警告:fgetcsv()期望参数1是resource,boolean在/home/ratena/public_html/proc_files/testcsv.php第6行给出

<?php
$uploadcsv = "/home/ratena/public_html/temp/files/BatchLoadPM15.csv";
$filecsv = file_get_contents($uploadcsv);
//$batchid = $_POST['batchid'];
$handle = fopen("$filecsv", "r");
while (($data = fgetcsv($handle, 100000, ",")) !== FALSE) {
print_r($data);
}
?>

最佳答案

这部分有问题

/* this is un-necessary */
$filecsv = file_get_contents($uploadcsv);
/* this expecting a file in */
$handle = fopen("$filecsv", "r");

试着用这个来替换这三行
$handle = fopen($uploadcsv, 'r');

跳过第一行
$column_headers = array();
$row_count = 0;
while (($data = fgetcsv($handle, 100000, ",")) !== FALSE)
{
if ($row_count==0)
{
$column_headers = $data;
}
else
{
print_r($data);
}
++$row_count;
}

关于php - 使用fgetcsv时PHP返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4327833/

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