gpt4 book ai didi

php:目录名+文件名

转载 作者:可可西里 更新时间:2023-10-31 22:41:48 28 4
gpt4 key购买 nike

我正在制作一个用 PHP 上传文件的表单。这些是我的输入:

 $file_name = filter_input(INPUT_POST, 'file_name');
$file = filter_input(INPUT_POST, 'file');
$file_date = filter_input(INPUT_POST, 'premiere_date');
$file_director = filter_input(INPUT_POST, 'director_name');

这就是我不知道我做错了什么:

if ((filter_input(INPUT_POST, 'submit'))) { //if submit button is clicked
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["file"]["file_name"]);
move_uploaded_file($_FILES["file"]["tmp_name"], $target_file);
echo $target_file;
}

这是html

 <form id="savingFiles" action="upload.php" method="post" enctype="multipart/form-data">
<label>Name of the file:</label>
<input type="text" name="file_name" value="<?php if (isset($row['file_name'])) {
echo $row['file_name'];
} ?>"/>
<br>
<label>Select your file:</label>
<input type="file" name="file" value="<?php if (isset($row['file'])) {
echo $row['file'];
} ?>"/>
<br>Date of premiere:
<input type="date" name="premiere_date" value="<?php if (isset($row['premiere_date'])) {
echo $row['premiere_date'];

} ?>"/>
<br>
<label>Name of the director:</label>
<input type="text" name="director_name" value="<?php if (isset($row['director_name'])) {
echo $row['director_name'];
} ?>"/>
<br>
<button type="submit" value="submit" name="submit">Upload file</button>
</form>

<?php
//Table with records
$sql = "SELECT myFilms.id, file_name, file, premiere_date, director_name FROM myFilms JOIN myFilms_directors ON myFilms.director_id = myFilms_directors.id";
/*for mysqlia
* $result = $conn->query($sql);
*/
/*for mysql (old)*/
$result = mysql_query($sql);

if ($result) {

echo "<table border='1' id='filesResults'><tr><th>FILE ID</th><th>FILE NAME</th><th>FILE</th><th>PREMIERE DATE</th><th>DIRECTOR NAME</th></tr>";


/* in mysqli
* while ($row = $result->fetch_assoc()) */
/*for mysql (old)*/
while ($row = mysql_fetch_array($result)) {

echo '<tr><td>' . $row['id'] . '</td><td>' . $row['file_name'] . '</td><td><a href= "'. $row['file']. ' ">view file</a></td><td>' . $row['premiere_date'] . '</td><td>' . $row['director_name'] . '</td></tr>';
}
echo "</table>";
} else {
echo "there is not data on the table";
}
/*for mysqli
$conn->close();
*/
/*for mysql (old)*/
mysql_close($dbhandle);

?>

所以,当我回显 $target_file 时,我希望它是本例中的路径 uploads/nameOfTheFile.pdf 但它只显示为 uploads/所以 $target_dir,我使用的是 basename 函数吗?我检查了 w3schools,它似乎适合我,但肯定有问题......

谢谢大家!!

最佳答案

改变
$target_file = $target_dir 。基本名称($_FILES["file"][“文件名”]);

$target_file = $target_dir 。 basename($_FILES["文件"]["名称"]);

应该可以。

关于php:目录名+文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31983172/

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