【发布时间】:2014-10-14 23:08:08
【问题描述】:
我想检查上传到我的 OpenShift 应用程序的文件是否具有文本扩展名(.txt 或 .tab)。根据given here 的一些建议,我编写了以下代码,并添加了回声以帮助调试:
$AllowedExts = array('txt','tab');
echo "AllowedExts: " . $AllowedExts[0] . " and " . $AllowedExts[1] . "<br>";
$ThisPath = $_FILES['uploadedfile']['tmp_name'];
echo "ThisPath: " . $ThisPath . "<br>";
$ThisExt = pathinfo($ThisPath, PATHINFO_EXTENSION);
echo "ThisExt: " . $ThisExt . "<br>";
if(!in_array($ThisExt,$AllowedExts) ) {
$error = 'Uploaded file must end in .txt or .tab';
}
echo "error echo: " . $error . "<br>";
在上传任何文件时,回显的响应是:
AllowedExts:txt 和制表符
此路径:/var/lib/openshift/************/php/tmp/phpSmk2Ew
这个分机:
错误回显:上传的文件必须以 .txt 或 .tab 结尾
这是否意味着 OpenShift 会在上传时重命名文件?如何获取原始文件名,然后检查其后缀?更一般地说,有没有更好的方法来检查文件类型?
【问题讨论】: