Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在OpenShift上使用php检索原始上传的文件名_Php_Openshift - Fatal编程技术网

在OpenShift上使用php检索原始上传的文件名

在OpenShift上使用php检索原始上传的文件名,php,openshift,Php,Openshift,我想检查上传到我的OpenShift应用程序的文件是否有文本扩展名.txt或.tab。根据一些建议,我编写了以下代码,并添加了回音以帮助调试: $AllowedExts = array('txt','tab'); echo "AllowedExts: " . $AllowedExts[0] . " and " . $AllowedExts[1] . "<br>"; $ThisPath = $_FILES['uploade

我想检查上传到我的OpenShift应用程序的文件是否有文本扩展名.txt或.tab。根据一些建议,我编写了以下代码,并添加了回音以帮助调试:

$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和tab

此路径:/var/lib/openshift/************/php/tmp/phpSmk2Ew

本文:

错误回显:上载的文件必须以.txt或.tab结尾

这是否意味着OpenShift在上传时正在重命名文件?如何获取原始文件名并检查其后缀?一般来说,是否有更好的方法检查文件类型?

$\u FILES['uploadedfile']['tmp\u name']包含服务器上可以使用move\u uploaded\u file移动的临时文件的名称。如果要检查客户端计算机上上载文件的原始名称,请使用$\u FILES['uploadedfile']['name']

这不是一个开放的转换问题,这是PHP的标准方式

有关详细信息,请参阅


有关检测文件类型的其他方法,请参见

,非常感谢-我以前甚至使用过它,但忘记了它-呸!你能解释一下为什么php会这样做,而不是仅仅将$u文件['uploadedfile']['name']指向文件内容吗?我在手册中找不到对此的解释。这是安全功能吗?很高兴我能帮忙!我不知道tmp_名称存在的确切原因,但我认为主要是因为某些文件系统无法处理每个字符。在Linux中,我可以在文件名中添加诸如换行符或问号等在windows服务器上不起作用的内容。tmp_名称仅包含适合每个常见文件系统的字符。