php - 在 PHP 中将变量作为我的文件名会忽略句号
问题描述
这可能是一个简单的问题,但我有点挣扎。
$filename = $_GET['type'];
$data = file_get_contents($filename.json);
当我访问我的网站 www.site.com/report.php?type=1
我得到错误:
file_get_contents(1json): failed to open
为什么忽略句号给我一个错误的文件名(应该是1.json)
解决方案
这是连接字符串的方式:
$data = file_get_contents($filename.".json");
推荐阅读
- fastapi - FastAPI graphql 订阅
- r - 如何在使用 tidymodels 时取消缩放和理解 glmnet 系数?
- mongodb - MongoDB Spring 聚合排除不起作用
- powershell - PowerShell Set-Partition -NewDriveLetter 返回 Set-Partition:请求的访问路径已在使用中。活动 ID {
- javascript - 二进制插入,数组的后半部分没有被递归调用?
- arrays - mongoose - 如何使用带有请求参数数组的 $in 进行 .find() 现在它只返回空数组
- javascript - 类型错误:fs.reddirSync 不是函数
- python - ValueError: matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 2 is different from 1)
- java - MySQL 语句取消计时器未能停止
- asymptote - 重新缩放渐近线图片大小但将文本保持为一致大小