I am trying to open a CSV file by using the JavaScript
prompt function. So far I can successfully fetch the file name, however when I pass it to fopen()
function in PHP to actually read the file, then it shows errors.
Please don't think that I just post this question. I read the previous question on StackOverflow, however, they don't work in my use case
CSV file name "data.csv"
Name, Class, Roll
zjvc, 11, 012
sahlk, 12, 154
jvcxj, 9, 145
<?php
echo "<script type='text/javascript'> let fid = prompt('Enter file name'); </script>"; // ask for file name
$file_name = "<script type='text/javascript'> document.write(fid); </script>"; // read data from prompt
$data_file = "$file_name.csv";
echo"$data_file";
$handle=fopen($data_file,'r');
$data = fgetcsv($handle,10000,",");
$all_record_arr = [];
while( ($data = fgetcsv($handle,10000, ",")) !== FALSE)
{
$all_record_arr[] = $data;
}
fclose($handle);
?>
Warnings
Prompt