Question

I have been scratching my head over why my code didn't work for a couple of days now (since when I printed my variables out they were fine, but wouldn't record into the database) but now I realized that the issue is that PHP isn't reading the CSV file (basically what I needed to do was take a CSV file, and port it to a PostgreSQL database).

I now realize that the reason it doesn't work is because I am executing the code through the command line when trying to write to the database, but in the browser when testing.

This led me to realize that the file isn't being read when I execute the code through cmd. The CSV file is too big to execute in a browser and causes an internal server error so I have to execute it through cmd, and yet when I do, it doesn't read the file, so how would I go about fixing that?

Was it helpful?

Solution

Most likely you have file owner/permission problems. When you execute script in browser it is exectuted as user www-data (or whatever your user is). When you run from command line you run it as yourself, which is another user.

Either change file permissions or run your script from web user, for example

sudo -u www-data php yourscriptname.php
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top