gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 22:44:21 25 4
gpt4 key购买 nike

我有一个程序可以获取用户输入并将其更改为文件或允许用户上传文件。我在从用户那里获取上传的文件时遇到问题。现在,我将其硬编码为我上传的名为 sample.fasta 的示例文件。我希望能够获取用户上传的文件的名称,然后使用该文件的名称调用我的程序。

我会贴出关于这个问题的所有相关代码。

这个页面叫做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>

此文件名为 upload.php 以及我用来上传文件的表单。

 <?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');
?>

所以基本上在我的 exec 函数中而不是读取 sample.fasta,我需要读取用户上传的文件...

最佳答案

您可以简单地将您的表单发布回包含该表单的页面,然后该页面将包含您上传的文件名和位置,以执行您需要对其执行的任何其他操作。

为此,您可以检查您的发布值是否设置在 PHP 文件的开头,如果它们与您在 upload.php 文件中所做的一样,则进行处理。

关于php - 如何获取添加到目录的最后一个文件的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30086540/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com