我有一个用于上传文本文件的html表单:
<div class="form">
<h3>Upload File:</h3>
<form action="networkSelector.php" method="post" enctype="multipart/form-data" name="FileUploadForm" id="FileUploadForm">
<label for="UploadFileField"></label>
<input type="file" name="UploadFileField" id="UploadFileField" />
<input type="submit" name="UploadButton" id="UploadButton" value="Upload" />
</form>
</div>
表单代码的php部分:
<?php
require('db.php');
include("auth.php");
if(isset($_FILES['UploadFileField'])){
// Creates the Variables needed to upload the file
$UploadName = $_FILES['UploadFileField']['name'];
$UploadName = mt_rand(100000, 999999).$UploadName;
$UploadTmp = $_FILES['UploadFileField']['tmp_name'];
$UploadType = $_FILES['UploadFileField']['type'];
$FileSize = $_FILES['UploadFileField']['size'];
// Removes Unwanted Spaces and characters from the files names of the files being uploaded
$UploadName = preg_replace("#[^a-z0-9.]#i", "", $UploadName);
// Upload File Size Limit
if(($FileSize > 125000)){
die("Error - File too Big");
}
// Checks a File has been Selected and Uploads them into a Directory on your Server
if(!$UploadTmp){
die("No File Selected, Please Upload Again");
}else{
move_uploaded_file($UploadTmp, "C:/xampp/htdocs/meg/$UploadName");
}
}
?>
它运行良好,如'move_upload_file命令所示,它将它们直接放入该目录。
然而,我想要实现的是使用此表单上传这些文件,然后将其添加到同一页面上的另一个表单。
以下是我的另一种形式的示例:
<form action="networkCompiler.php" method="POST">
<h3>Choose Network/Function:</h3>
<select id ="network" name="network" />
<option value="networkA">A</option>
<option value="networkB">B</option>
</select>
理想情况下,如果我在第一个表单上上传networkC,我希望它然后显示在第二个表单上。我主要在这个项目上使用PHP,并试图找到该语言的解决方案。到目前为止,我已尝试将文件上传保存为变量,然后将其添加到表单的底部。
<?php
if (isset($_POST['UploadButton'])) {
if (is_uploaded_file($_FILES['UploadFileField']['tmp_name'])) {
$trying = $_POST['FileUploadForm'];
}
}
?>
任何输入都将不胜感激。谢谢。
答案 0 :(得分:0)
使用file_get_contents()
:
<?php
if(your_condition)
echo '<option value="the_value_you_want">' . file_get_contents('path_of_uploaded_file') . '</option>';
?>