【发布时间】:2019-04-24 13:26:24
【问题描述】:
我正在尝试创建一个简单的“在 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
?>
【问题讨论】:
-
所以上传提供的文件,获取它的路径并使用这个路径。 手册如何用php上传文件无处不在。
-
您是否在 Google 上搜索过“PHP 上传文件示例”?你应该找到你需要的一切
-
您应该已经从上一个问题中知道这是如何工作的 - stackoverflow.com/questions/55769444/…