PHP 图片上传,将名称设置为图片 HTML 输入名称=""
PHP Image upload, set name as the image HTML Input name=""
我想将图像的名称设置为与 name="" 字段相同。
这是我设置图片上传时的名字的地方,这里是XXXX,这里是我要输出name="front"中存储的名字'front'在 HTML 文件中输入:
$custom_name = "[" . "CANON" . "]_" . "XXXXXX";
HTML:
<form method="POST" class="admin_image_form" action="" enctype="multipart/form-data">
<div class="input-tag">Front</div>
<label class="upload-button">
<input type="file" name="front">
Choose Image
</label><br>
</form>
我尝试用“$_FILES['front']['name']
”替换XXXX
,但这只是将上传的文件名设置为“CANON_.png
”,后跟图像的原始名称,我想要它是 'CANON_front.png
' 和 'front
' 来自 html
中的 name="front"
感谢您的帮助。
将您的表单更改为此input hidden="front"
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$( document ).ready(function() {
$( "#new" ).hide();
});
</script>
<form method="POST" class="admin_image_form" action="" enctype="multipart/form-data">
<div class="input-tag">Front</div>
<label class="upload-button">
<input id="new" style="color: white;" type="hidden" name="front" />
<input type="file" name="file">
Choose Image
</label><br>
</form>
<?php
$custom_name = "[" . "CANON" . "]_" . "XXXXXX";
$_FILES['front']['name']
?>
您可以简单地为 FILES 数组的名称分配一个变量,然后在其后加上一个连接的下划线和文件名,前面是 "CANON".
$file = $_FILES['front']['name'];
$new_name = "CANON" . "_" . $file;
我想将图像的名称设置为与 name="" 字段相同。
这是我设置图片上传时的名字的地方,这里是XXXX,这里是我要输出name="front"中存储的名字'front'在 HTML 文件中输入:
$custom_name = "[" . "CANON" . "]_" . "XXXXXX";
HTML:
<form method="POST" class="admin_image_form" action="" enctype="multipart/form-data">
<div class="input-tag">Front</div>
<label class="upload-button">
<input type="file" name="front">
Choose Image
</label><br>
</form>
我尝试用“$_FILES['front']['name']
”替换XXXX
,但这只是将上传的文件名设置为“CANON_.png
”,后跟图像的原始名称,我想要它是 'CANON_front.png
' 和 'front
' 来自 html
name="front"
感谢您的帮助。
将您的表单更改为此input hidden="front"
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$( document ).ready(function() {
$( "#new" ).hide();
});
</script>
<form method="POST" class="admin_image_form" action="" enctype="multipart/form-data">
<div class="input-tag">Front</div>
<label class="upload-button">
<input id="new" style="color: white;" type="hidden" name="front" />
<input type="file" name="file">
Choose Image
</label><br>
</form>
<?php
$custom_name = "[" . "CANON" . "]_" . "XXXXXX";
$_FILES['front']['name']
?>
您可以简单地为 FILES 数组的名称分配一个变量,然后在其后加上一个连接的下划线和文件名,前面是 "CANON".
$file = $_FILES['front']['name'];
$new_name = "CANON" . "_" . $file;