PHP finding file where post INCLUDES portion of filename -


i posting variable php process in attempt find file in directory.

the problem filename longer user submit. submit voyage number looks this:

222ine 

whereas filename this:

cmdu-ymunicorn-222ine-23082016.txt 

so need php able directory, find file has matching voyage number, , confirm it's existence (i need able download said file, that'll different question if can't figure out).

anyways, here php process takes posted variable:

<?php   if($_post['voyage'] == true)   {     $voyage = mysqli_real_escape_string($dbc, $_post['voyage']);     $files = glob("backup/................."); // <-this voyage go     // should     // $files = glob("backup/xxxx-xxxxxxxx-222ine-xxxx.txt");      if(count($files) > 0)     {       foreach($files $file)       {         $info = pathinfo($file);         echo "file found: " . $info["name"];       }     }     else     {       echo "file doesn't exist";     }   } ?> 

the filename begin cmdu. second part may vary. voyage number. the date, followed txt.

i hope makes sense.

if can help, i'd appreciate it.

ok, first, must directory listing

<?php   if($_post['voyage'] == true)   {     $voyage = $_post['voyage']; //in case not important escape     $files = scandir("backup"); // <-this voyage go ***here use dir listing***    unset($files[0], $files[1]) // remove ".." , ".";      if(count($files) > 0)     {       $filefound = false;       foreach($files $file)       {          if((preg_match("/$voyage/", $file) === 1)){           echo "file found: $file \n";           $filefound = true;         }        }        if(!$filefound) die("file $voyage doesn't exist"); // after loop ends, if no file print "no file"     }     else     {       echo "no files in backup folder"; //if count === 0 means no files in folder     }   } ?> 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -