I am wanting to change the name of a file that the user uploads to the 'job_id'.fasta. Right now it just stays as whatever the user called it when uploaded. I also want to keep the extension of .fasta on the file.
This form is from home.php. It is the form that the user uploads the file with
<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 upload.php. My comments are going to explain my thought process. But if someone could help me finish it off I would greatly appreciate it.
<?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');
?>