Search the Community
Showing results for tags 'fgcsv'.
-
I am very new to php and I have seen many posts on how to write to a csv file and several on how to fgetcsv data from a file, but none of it really makes sense and I cannot find a relevant example of what I am attempting to do. I know that most will say, use mySQL, but for this example, I really want to know how to use a csv as a data source. I have a php script that creates an image gallery from the folder that it is placed. It also gets and displays the embedded image attributes, filename, file dimensions, file size. Rather than display the file dimensions and file size, I want a corresponding csv file to display an image Category and other details from the csv. The full original php script can be viewed here: http://www.mahogan.com/gallery.txt The modified working model of this gallery can be viewed here: http://www.mahogan.com/sandbox/thumbs/gallery.php Here is a php script that gets the data from the csv: http://www.mahogan.com/sandbox/thumbs/gallery-fgetcsv.php echo "<html><body><table>\n\n"; $f = fopen("gallery-data.csv", "r"); while (($line = fgetcsv($f)) !== false) { echo "<tr>"; foreach ($line as $cell) { echo "<td>" . htmlspecialchars($cell) . "</td>"; } echo "<tr>\n"; } fclose($f); echo "\n</table></body></html>"; In my examples of the csv, this just prints the entire csv in an html table as in the file. What I do not understand is this: 1) How to Match the Filename with the thumbnail filename in the folder so that all the data in that row will stay with that filename. 2) How to assign/replace this csv data to print these in place of the image attributes. Any advice with using this CSV as a data source would be very appreciated as I really want to learn how to do this! Thanks!