如何获取添加到目录的最后一个文件的名称

I have a program that either gets user input and changes it into a file or allows the user to upload a file. I am having an issue getting the uploaded file from the user. Right now I have it hardcoded for a sample file that I uploaded called sample.fasta. I want to be able to get the name of the file that the user uploaded, and then call my program using the name of that file.

I will post all the relevant code about this question.

This page is called blast.php

<?php
if(isset($_POST['submit2'])){
            //echo "submit2";
    //      echo $_FILES['uploadedfile']['name'];

     //declare variables to what the user defines them as
            $db = $_POST['database'];
            $evalue = $_POST['evalue'];
            $sequence = $_POST['BlastSearch'];
            $hits = $_POST['hits'];
            $userid = $_SESSION['uid'];

            //insert the values into the database
            $mysqli->query("INSERT INTO `Job` (`uid`, `input`, `status`, `start_time`, `finish_time`) VALUES ('1', 'used a file', 'running' , NOW(), NOW())");

            $mysqli->query("INSERT INTO `BLAST`(`db_name`, `evalue`, `job_id`) VALUES ('" . $db . "','" . $evalue . "', '".$mysqli->insert_id."')") or die(mysqli_error($mysqli));

            //need to change the name of sample.fasta to whatever file uploaded
            exec('/students/groups/cs4380sp15grp4/blast/blast-2.2.26/bin/blastall -p blastp -d db -i /students/groups/cs4380sp15grp4/public_html/home/uploads/sample.fasta -m '.$evalue.' -o outputFILE -v '.$hits.' -b '.$hits);
?>
          <form enctype="multipart/form-data" action="upload.php" method="POST" class="form-inline">
                            <input type="file" name="fileToUpload" id="fileToUpload" class="form-control"/>
                            <input type="submit" value="upload" name="upload" class="form-control"/>
                            <input type="reset" value="reset" name="reset" class="form-control"/>
            </form>

This file is called upload.php and the form I use to upload the file.

 <?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$FileType = pathinfo($target_file,PATHINFO_EXTENSION);

// Allow certain file formats
if($FileType != "fasta" ) {
    echo "Sorry, only fasta files are allowed.";
    $uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
    echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file))     {

    echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
    echo "Sorry, there was an error uploading your file.";
}
}
header('Location: http://babbage.cs.missouri.edu/~cs4380sp15grp4/home/blast.php');
?>

So basically in my exec function instead of reading sample.fasta, I need to read the file that the user uploads...

You could simply post your form back to the page that has the form on it, which would then have your uploaded file name and location to do whatever else you need to do with it.

To do this, you could check to see if your post values are set at the beginning of the PHP file and do your processing if they are just like you did on your upload.php file.

Change in your upload.php last line to:

header('Location: http://babbage.cs.missouri.edu/~cs4380sp15grp4/home/blast.php?file='.urlencode($target_file));

and check $_GET in your blast.php:

if(isset($_GET['file'])){
    $fastaFile = $_GET['file']
....