-
-
Save fahmiardi/4c7b1c0f82fb4f8e85b6d25969606821 to your computer and use it in GitHub Desktop.
Shows how to read a CSV stored in S3 using the AWS SDK for PHP's S3 Stream Wrapper.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require __DIR__ . '/vendor/autoload.php'; | |
$s3 = Aws\S3\S3Client::factory($config); | |
$s3->registerStreamWrapper(); | |
$url = 's3://{$bucket}/{$key}'; | |
// Read CSV with fopen | |
$file = fopen($url, 'r'); | |
$keys = fgetcsv($file); | |
while (!feof($file)) { | |
$row = array_combine($keys, fgetcsv($file)); | |
print_r($row); | |
} | |
// Read CSV with SplFileObject | |
$file = new \SplFileObject($url, 'r'); | |
$keys = $file->fgetcsv(); | |
while (!$file->eof()) { | |
$row = array_combine($keys, $file->fgetcsv()); | |
print_r($row); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment