【发布时间】:2015-07-17 12:05:25
【问题描述】:
我想更改用户上传到“job_id”.fasta 的文件的名称。现在它只是保持用户在上传时调用它的任何内容。我还想在文件中保留 .fasta 的扩展名。
此表单来自 home.php。它是用户上传文件的形式
<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。我的 cmets 将解释我的思考过程。但如果有人能帮我完成它,我将不胜感激。
<?php
//get the max job_id from the Job table
$fileID = mysqli_query("SELECT MAX(job_id) FROM Job");
//I have to increment it once because we do not actually insert a new job_id yet.
$fileID = $fileID + 1;
// declare the file path
$target_dir = "uploads/";
//here we are creating the file name. I think I need the change something here
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
//get the file extension
$FileType = pathinfo($target_file,PATHINFO_EXTENSION);
//$target_file = $target_dir . $fileID . "'.'" $FileType;
$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: blast.php');
?>
【问题讨论】:
-
stackoverflow.com/questions/2562851/… 享受...发帖前先搜索一下。
标签: php mysql database file primary-key