簡體   English   中英

在OpenShift上使用php檢索原始上傳的文件名

[英]Retrieve original uploaded filename using php on OpenShift

我想檢查上傳到我的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和制表符

ThisPath:/ var / lib / openshift / ************ / php / tmp / phpSmk2Ew

ThisExt:

錯誤回顯:上傳的文件必須以.txt或.tab結尾

這是否意味着OpenShift會在上傳時重命名文件? 如何獲取原始文件名,然后檢查其后綴? 更一般而言,是否有更好的方法來檢查文件類型?

$_FILES['uploadedfile']['tmp_name']包含服務器上臨時文件的名稱(可以使用move_uploaded_file()進行移動)。 如果要在客戶端計算機上檢查上載文件的原始名稱,請使用$_FILES['uploadedfile']['name']

這不是Open Shift問題,而是PHP的標准方法。

有關更多詳細信息,請參見http://php.net/manual/en/features.file-upload.post-method.php

有關檢測文件類型的其他方法,請參見http://php.net/manual/en/ref.fileinfo.php

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM