fopen 与 cron 作业

use*_*494 5 php cron

有人可以告诉我我做错了什么吗?我有一个 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
Run Code Online (Sandbox Code Playgroud)

报告.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));
}
?>
Run Code Online (Sandbox Code Playgroud)

csv 文件应存储在

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

我在这里缺少什么?TIA

Jas*_*els 4

您没有保存到正确的目录。相反做

$fp = fopen(__DIR__ . "/reports/report.csv" , "w+");
Run Code Online (Sandbox Code Playgroud)