gpt4 book ai didi

php - fopen 与 cron 工作

转载 作者:行者123 更新时间:2023-12-01 23:24:46 24 4
gpt4 key购买 nike

有人可以告诉我我做错了什么吗?我有一个 php 脚本,它应该使用 cron 作业执行,从数据库中提取数据并将其放入 csv 文件中。
当我从浏览器运行它时,它工作得很好,所以我确定我的查询是正确的。但是,当我使用 cron 作业时,它返回“ 未指定输入文件。”并且不写入文件。

这是我的代码:

克朗:

/home/ACCOUNT_NAME/public_html/directory/report.sh



报告.sh
php -q /home/ACCOUNT_NAME/public_html/directory/report.php
php -q /home/ACCOUNT_NAME/public_html/directory/report_mail.php

报告.php
<?php

$con = mysql_connect("localhost", "my_un", "my_pw") ;

if(!$con){
die('Could not connect: ' . mysql_error()) ;
}
mysql_select_db("my_db", $con) ;

if (!function_exists('fputcsv')){
function fputcsv($objFile,$arrData,$strDelimiter=',',$strEnclose='"') {
$strNewLine="\n";
$strToWrite = '';
foreach ($arrData as $strCell){
//Test if numeric
if (!is_numeric($strCell)){
//Escape the enclose
$strCell = str_replace($strEnclose,$strEnclose.$strEnclose,$strCell);
//Not numeric enclose
$strCell = $strEnclose . $strCell . $strEnclose;
}
if ($strToWrite==''){
$strToWrite = $strCell;
} else {
$strToWrite.= $strDelimiter . $strCell;
}
}
$strToWrite.=$strNewLine;
fwrite($objFile,$strToWrite);
}
}

// CUT - MY QUERY HERE


$fp = fopen("/reports/report.csv" , "w+");

foreach ($list as $line) {
fputcsv($fp, split(',', $line));
}
?>

csv文件应该存储在

/home/ACCOUNT_NAME/public_html/directory/reports/report.csv



我在这里缺少什么? TIA

最佳答案

您没有保存到正确的目录。而是做

$fp = fopen(__DIR__ . "/reports/report.csv" , "w+");

关于php - fopen 与 cron 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14656099/

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