【发布时间】:2019-01-26 09:18:41
【问题描述】:
我已经创建了一个基本的上传表单,上传一切正常,但我无法找到将文件描述添加到页面的方法。我希望它在“描述”下出现: uploads page
HTML 表单:
<form action="/scripts/upload.php" method="POST" enctype="multipart/form-data">
Select a file to upload:
<input type="file" name="fileToUpload" id="fileToUpload"><br />
<textarea id="FileDescription" name="FileDescription" rows="1" placeholder="*File description" required></textarea> <br />
<input type="submit" value="Upload File" name="submit">
脚本:
<?php
$target_dir = "../uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$df = disk_free_space("../uploads/");
if (isset($_POST["submit"])) {
$check = filesize($_FILES["fileToUpload"]["tmp_name"]);
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > $df) {
echo "Sorry, your file is too large.";
$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.";
}
}
?>
【问题讨论】:
-
图片显示一个 jpeg 图片和一个 html 文件... html 文件是评论吗?
-
你的意思是你希望描述出现在目录的apache目录列表中吗??
-
表单是我使用的 HTML 页面。照片只是显示文件和描述应该去的上传页面。那里的文件正是我用来测试它是否正常工作的文件。编辑:是的,这就是我的意思。
标签: php file-upload field-description