我正在尝试在输入按钮下方显示上传文件的名称。一旦文件被选中并添加到服务器“file_name.ext上传”,默认文本应该说“No File Uploaded”。
此处是我的代码:
<label for='upload' class='upload-button'></label><input type='file' name="fileAttach" class='upload-button' id='upload'/><br>Upload Site List
<?php
if (isset($_FILES['fileAttach']['name'])) {
echo "File is attached.";
}
?>
此代码位于表单页面上,使用带有enctype multipart / form-data的POST。
我的知识低于入门级,所以如果这是一个非常简单的问题,我很抱歉。到目前为止我找到的所有信息都无济于事。
答案 0 :(得分:0)
<label for='upload' class='upload-button'></label><input type='file' name="fileAttach" class='upload-button' id='upload'/><br>Upload Site List
<?php
if(isset($_FILES['fileAttach']['name'])) {
echo $_FILES['fileAttach']['name']." was uploaded";
}else{
echo "No File Uploaded";
}
?>
答案 1 :(得分:0)
表单必须提交给php以回应声明。
<form enctype="multipart/form-data" action="" method="POST">
<input type='file' name="fileAttach" class='upload-button' id='upload'/>
<input type="submit">
</form>
<br>Upload Site List<br>
<?php
if(isset($_FILES['fileAttach']['name'])) {
echo $_FILES['fileAttach']['name'] . " was uploaded";
} else {
echo "No File Uploaded";
}
?>