PHP图片上传,将名称设置为图像HTML输入名称=“”(PHP Image upload, set name as the image HTML Input name=“”)

编程入门 行业动态 更新时间:2024-10-25 23:21:12
PHP图片上传,将名称设置为图像HTML输入名称=“”(PHP Image upload, set name as the image HTML Input name=“”)

我想将图像的名称设置为与name =“”字段相同。

这是我在上传图像时设置图像的名称,XXXX所在的位置,这就是我要输出的名称'front',它存储在HTML FILE输入中的name =“front”中:

$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 ',然后是图像的原始名称,我希望它是'带有' front '的CANON_front.png '来自html中的name="front"

谢谢你的帮助。

I would like to set the name of the image to be the same as the name="" field.

This is where I set the name of the image when its been uploaded, where the XXXX is, this is where I want to output the name 'front' that is stored in name="front" in the HTML FILE Input:

$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>

I have tried replacing the XXXX with '$_FILES['front']['name']' however this just sets the uploaded file name to 'CANON_.png' followed by the original name of the image, I want it to be 'CANON_front.png' with 'front' coming from the name="front" in html

Thanks for any help.

最满意答案

您可以简单地将一个变量分配给FILES数组的名称,然后使用后面的文件名添加连接的下划线,前面是“CANON”。

$file = $_FILES['front']['name']; $new_name = "CANON" . "_" . $file;

You can simply assign a variable to the FILES array's name and then tack on a concatenated underscore with the file name after it, that is preceded by "CANON".

$file = $_FILES['front']['name']; $new_name = "CANON" . "_" . $file;

更多推荐

'front',XXXX,class,电脑培训,计算机培训,IT培训"/> <meta name="

本文发布于:2023-08-04 14:08:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1415923.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:名称   设置为   图片上传   图像   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!