Question

The following script works fine on browser. But in cron job it gives an error.

fgetcsv expect parameter 1 to be resource,boolean given

Please help.

Code:

$handle = fopen("http://www.spc.noaa.gov/climo/reports/today_hail.csv", "r");

while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    $import="INSERT into mytable Values('" . mysql_real_escape_string($data[0]) . "','$data[1]','" . mysql_real_escape_string($data[2]) . "','" . mysql_real_escape_string($data[3]) . "','" . mysql_real_escape_string($data[4]) . "','$data[5]','$data[6]','" . mysql_real_escape_string($data[7]) . "')";

    mysql_query($import) or die(mysql_error());        
}
fclose($handle); 
Was it helpful?

Solution

It will be your permissions.

Ensure that your permissions & file ownership are configured correctly, being able to run from the browser but not from cron almost always indicates a permission problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top