我正在尝试创建一个简单的“在php中上传csv文件Web表单”,该格式需要一个csv文件,并转换为json。文件1,finder.php
这是/ finder.php
(文件#1,网络表单)
echo '<div class="wrap"><h1>Step 1.) Upload the First .CSV file below. So, we can use it as data!</h1>';
echo '<form action="/upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="csv" value="" />
<input type="submit" name="submit" value="Save" /></form>';
这里是文件2的功能; / upload.php
我可以使用绝对文件路径;但我需要它成为从上传页面到上传处理程序的变量。
<?php
echo "<h2>Uploading....</h2>";
$file= fopen('assets/files/locationsCSV.csv', 'r'); #needs to be variable from upload screen
$csv= file_get_contents($file);
$array = array_map("str_getcsv", explode("\n", $csv));
file_put_contents("assets/files/locationsCSV.json",json_encode($array)); #needs to be variable from upload screen
?>