php - 如何将文件上传到两个不同的文件夹
问题描述
我无法将 2 个文件上传到 2 个不同的文件夹。我只能将一个文件上传到一个选定的文件夹。
这是它的屏幕截图:
这是代码:
<form name="form_id" id="form_id" action="javascript:void(0);" enctype="multipart/form-data" style="width:800px; margin-top:20px;">
<div class="row">
<div class="col-lg-12">
<label class="fieldlabels">Documentation:</label> <br>
<input type="file" name="vasplus_multiple_files" id="vasplus_multiple_files" accept="application/pdf" multiple="multiple"/><br>
<!--input type="submit" value="Upload" /--><br>
<table class="table table-striped table-bordered" style="width:60%;" id="add_files">
<thead>
<tr>
<th style="color:blue; text-align:center;">File Name</th>
<th style="color:blue; text-align:center;">Status</th>
<th style="color:blue; text-align:center;">File Size</th>
<th style="color:blue; text-align:center;">Action</th>
<tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
<input type="submit" value="Upload" /><br>
</form>
<br/>
<form name="form_id2" id="form_id2" action="javascript:void(0);" enctype="multipart/form-data" style="width:800px; margin-top:20px;">
<div class="row">
<div class="col-lg-12">
<label class="fieldlabels">Photo:</label> <br>
<input type="file" name="vasplus_multiple_files2" id="vasplus_multiple_files2" multiple="multiple" accept="image/*"/><br><br>
<table class="table table-striped table-bordered" style="width:60%;" id="add_files2">
<thead>
<tr>
<th style="color:blue; text-align:center;">Photo Name</th>
<th style="color:blue; text-align:center;">Status</th>
<th style="color:blue; text-align:center;">File Size</th>
<th style="color:blue; text-align:center;">Action</th>
<tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
<input type="submit" value="Upload" /><br>
</form>
这是 upload.php 代码,在我刚刚上传到一个文件夹位置的代码中:
<?php
if(isset($_POST) && $_SERVER['REQUEST_METHOD'] == "POST")
{
$vpb_file_name = strip_tags($_FILES['upload_file']['name']); //File Name
$vpb_file_id = strip_tags($_POST['upload_file_ids']); // File id is gotten from the file name
$vpb_file_size = $_FILES['upload_file']['size']; // File Size
$vpb_uploaded_files_location = 'C:/xampp/htdocs/claim_210119/claim_file/document/'; //This is the directory where uploaded files are saved on your server
$vpb_final_location = $vpb_uploaded_files_location . $vpb_file_name; //Directory to save file plus the file to be saved
//Without Validation and does not save filenames in the database
if(move_uploaded_file(strip_tags($_FILES['upload_file']['tmp_name']), $vpb_final_location))
{
//Display the file id
echo $vpb_file_id;
}
else
{
//Display general system error
echo 'general_system_error';
}
}
?>
如何以两种不同的形式将文件上传到我电脑中的两个不同文件夹。有人可以帮忙吗?提前致谢。
解决方案
是否要将一个文件保存在位置 A 而另一个文件保存在位置 B?
您可以简单地使用提交按钮的name
属性来确定要PHP
归档的表单值,然后使用所需的位置。
因此,在 if 条件中添加另一个表达式,例如:
if (isset($_POST["form1"])) // name of first form's submit button
{
// Your desired location
}
else
{
// Your desired location
}
// Rest of your logic is applicable for any location :)
name
在两种形式的提交按钮中添加属性,例如:
<input type="submit" name="form1" value="Upload" />
和
<input type="submit" name="form2" value="Upload" />
推荐阅读
- unicode - 如何将二进制值分配给新符号?
- tomcat - Apache Tomcat - 将请求从一个文件夹重定向到另一个文件夹?
- arrays - SQL 中的 JSON 解析
- single-sign-on - 具有组成员身份的 Fusionauth Saml 登录
- python - 如何使用 GitHub API 在 Python 存储库中获取需求文件的路径?
- sql - SSRS 案例陈述
- python - 无法在 Pytest 中导入 .py 文件
- android - x 和 y 之间的一组随机数,需要是唯一的,使用 Kotlin
- javascript - 浮动图表饼工具提示未显示
- html - 使用 SASS 的动态间距类