我正在尝试使用 php 加载文件夹中的所有图像,然后构建一个表格并从 json 文件中提取文本并将其放在每个图像旁边。目标是让 json 看起来像这样。
{
"Car1": {
"year":"2012"
},
"Car2": {
"year":"2011"
},
"Car3": {
"year":"2009",
"milage":"10,204"
}
}
Run Code Online (Sandbox Code Playgroud)
Car1、Car2 名称最终也将与文件夹中实际图像的名称匹配。所以我想在 json 文件中获取图像和正确的部分,并构建一个将它们全部列出的表格。到目前为止,我有以下 php,但我不确定如何将它们放在一起,如下所示,它现在只是分开的。关于如何结合下面的 php 来实现我描述的结果的任何建议?
6/1 编辑(使用以下答案的新代码)。这是在我想要输出所有这些的地方的页面上,并且 &letter 变量是从另一个页面上的表单传递的。但是当那个表单提交并且这个页面被触发时,什么也没有发生。我做错了什么吗?
$letter = $_POST['letter'];
//Call the path of the cars for the chosen letter
$path = "/images/PartsCars/".$letter."/";
$temp_files = scandir($path);
//Call the path for the json file in the chosen letter subfolder
$data = json_decode($string, true);
//Sort the pictures in this folder alphabetically
natsort($temp_files);
echo '<table cellspacing="5" cellpadding="5">'; …Run Code Online (Sandbox Code Playgroud) 我正在使用 Multer 来获取在表单上上传的文件并将其保存在内存中,以便我可以解析它并吐出一些内容,但是有没有一种方法可以获取 zip 文件并能够解压缩它并仍然保留解压后的文件在内存中而不写入磁盘?我知道节点有一个名为“unzip”的 npm 模块,但它似乎只能从物理位置提取文件,除非我弄错了。我很感激任何见解!
const multer = require('multer');
const storage = multer.memoryStorage();
const upload = multer({ storage: storage, putSingleFilesInArray: true });
// landing page
router.get('/', function (req, res) {
res.sendFile(path.join(__dirname, '../../views', 'index.html'));
});
// parse multiple files from the form
router.post('/upload', upload.array('upload'), function (req, res) {
console.log(req.files);
});
Run Code Online (Sandbox Code Playgroud)