stackoverfloweth
stackoverfloweth

Reputation: 156

How can I open a .csv file in a folder regardless of name using PHP?

I've got a folder, and I've got a file. The file is test.csv, but it could get overwritten and become pickle.csv or sylvester.csv or ethiopia.csv, and so I need a way to open a single file in a folder which will always be a .csv file with the name changing all the time. I don't want to have to constantly change the name in the source. I want it automatic.

I essentially want to be able to do something like this:

$handle=fopen(glob("/Applications/XAMPP/xamppfiles/htdocs/SITEPREVIEW/csv_drop_folder/*.csv")[0],"r")


BACK STORY: Someone is scp-ing new content to a server and file names change, but function cannot.

Upvotes: 1

Views: 89

Answers (1)

marcellorvalle
marcellorvalle

Reputation: 1679

Supposing you have one single csv file. Try using glob function:

$csv = glob("$yourDirectory/*.csv")[0];

Upvotes: 1

Related Questions