ホームページ  >  記事  >  バックエンド開発  >  is_uploaded_file() 関数は PHP の関数です

is_uploaded_file() 関数は PHP の関数です

WBOY
WBOY転載
2023-09-07 09:37:02999ブラウズ

is_uploaded_file() 関数は PHP の関数です

is_uploaded_file() 関数は、ファイルが HTTP POST 経由でアップロードされたかどうかを確認します。ファイルが HTTP POST 経由でアップロードされた場合、この関数は TRUE を返します。失敗した場合は FALSE を返します。

構文

is_uploaded_file(file_path)

パラメータ

  • file_path -チェックするファイルを指定します。

Returns

ファイルが HTTP POST 経由でアップロードされた場合、is_uploaded_file() 関数は TRUE を返します。失敗した場合は FALSE を返します。

次の内容を含むファイル「new.txt」をアップロードするとします。

This is demo text!

<?php
   // checking for file is uploaded via HTTP POST
   if (is_uploaded_file($_FILES[&#39;userfile&#39;][&lsquo;new.txt&#39;])) {
      echo "File ". $_FILES[&#39;userfile&#39;][&lsquo;new.txt&#39;] ." uploaded successfully!</p><p>";
      // displaying contents of the uploaded file
      echo "Reading Contents of the file:</p><p>";
      readfile($_FILES[&#39;userfile&#39;][&lsquo;new.txt&#39;]);
   } else {
      echo "File ". $_FILES[&#39;userfile&#39;][&lsquo;new.txt&#39;] ." failed in uploading! File upload attack could       be the reason!</p><p>";
   }
?>

出力

File new.txt uploaded successfully!
Reading Contents of the file:
This is demo text!

ファイル「details.txt」を使用した別の例を見てみましょう。

ライブデモ

<?php
$file = "newdetailstxt";
if(is_uploaded_file($file)) {
   echo ("Uploaded via HTTP POST");
} else {
   echo ("Not uploaded via HTTP POST");
}
?>

出力

Not uploaded via HTTP POST!

以上がis_uploaded_file() 関数は PHP の関数ですの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事はtutorialspoint.comで複製されています。侵害がある場合は、admin@php.cn までご連絡ください。