2016-09-03 2 views
-1

こんにちは私は、PHPを使用してフォルダからファイルに文字列を一致させることが可能だろうかと思います。例えばphpを使ってフォルダからファイル名に文字列を一致させる

私はアップロードと内部という名前のフォルダを持って、私はimage1.pngimage2.jpgDOC1.DOC、およびdoc2.pdfなどの異なるファイルを持っています。

<?php 
$string = "image2"; 

// I need some function to display the image2 on my webpage. 
// If string "image2" is found in the uploads folder 
// then it should display the image 

?> 

ありがとう:私は私のPHPファイルにこのコードを持っていると仮定すると

答えて

0

私はこの1つはあなたがやりたいことだと思います

$dir = "uploads";//the path to your folder 
if(file_exists($dir)){ 
    if ($dh = opendir($dir)) { 
       while (($file = readdir($dh)) !== false) { 
        if (!is_dir($file)) { 

        if ($file == "image2"){ 
         // your code 
        } 
       } 
       } 
      } 
     } 
関連する問題