我试图在更改其他表单切换/参数时保留上传的文件信息,并避免每次都重新上传文件。是否可以保留文件上传数据?
表单的 HTML
<form method="POST" action="" enctype="multipart/form-data">
<input type="file" name="fileUpload" id="fileUpload">
<input type="submit" value="Upload This" name="upload">
<input type="submit" value="Preview" name="preview">
<div class="col text-center justify-content-center">
<div class="bmd-form-group">
<label class="bmd-label-static" for="txtcolor">Choose the Text Color</label>
<input type="color" id="txtcolor" name="txtcolor" value="#000000">
<label for="body">Body</label>
</div>
</div>
<div class="col text-center justify-content-center">
<div class="form-check">
<label class="form-check-label">
<input id="iversion" class="form-check-input" name="invertBox" type="checkbox" value="">Invert
<span class="form-check-sign">
<span class="check"></span>
</span>
</label>
</div>
</div>
<?php
if($previewOk){
echo "<img class='w-100 h-100' src='data:image/jpeg;base64, $imgData' />"; ?>
<?php } ?>
<a href="<?php $add_to_cart = do_shortcode('[add_to_cart_url id="'.$post->ID.'"]'); echo $add_to_cart;?>"class="more">Buy now</a>
</form>
PHP
$previewOk=0;
if($_FILES["fileUpload"]["tmp_name"]){
$myfile=$_FILES["fileUpload"]["tmp_name"];
}
if(!empty($_POST) && $_SERVER['REQUEST_METHOD'] == 'POST'){
$file_url = move_file_test(); //moves file to directory
$theid = create_download(); //creates a file link
create_download_version($theid, $file_url); //more file stuff
}
if(isset($_POST['txtcolor'])){
$color = $_POST['txtcolor'];
$myfile = change_color($myfile); //some function that alters the $myfile and regenenerates
}
if(isset($_POST["preview"])) {
$imgData = base64_encode(file_get_contents($myfile));
previewOk = 1;
}
我想$myfile在提交表单后留下来,只在上传不同的文件时更新。目的是$myfile再次以其他基于表单的操作进行访问 - 例如:更改上传的图像文件的背景颜色并预览它,而无需启动文件浏览器并重新开始每次迭代。
翻阅古今