Skip to content Skip to sidebar Skip to footer

Reading Csv File Into Javascript String Or Array

I'm having a very specific problem so I hope someone can help. I'm building a map app with a CakePHP backend framework. I'm currently attempting to import some data into my applica

Solution 1:

Solution 2:

If the file is local to the where your application is being served (is on the same server), you can use simple PHP file I/O.

<?php$filename = "/YOUR/FILE/URL/HERE.csv";
$file = fopen( $filename, "r" );
if( $file == false ) {
    echo"Error!";
    exit();
}
$csv_string = fread( $file, $filesize );
fclose( $file );
?>

mapbox.markers.layer().csv("<?phpecho$csv_string; ?>");
//Make sure you put the quotes around the php tag. Otherwise the JavaScript will not recognize it as a string.

(Derived heavily from http://www.tutorialspoint.com/php/php_files.htm). I hope this is what you're looking for.

Post a Comment for "Reading Csv File Into Javascript String Or Array"