根据表单中选定的选项重命名图像


Rename image according to selected option in form?

非常简单的问题。我有一个用HTML制作的选择选项框,当选择一个选项时,它会根据选项的名称重命名上传的图像。因此,当将图像上传到S3时,需要将其添加到重命名中。就像这样:

$actual_image_name = $hotelDir . '-' . date("Y-m-d_H:i:s"). "_" . $size . ".".$ext;

$hotelDir实际上是房间类型或我们设置的任何类型。

以下是任何想看它的人的列表示例。

<select class="typeSelect" name="roomType" id="typeSelect" required="true">
                                <optgroup label="Main Areas">
                                    <option value="ext" name="ext">Exterior</option>
                                    <option value="grm" name="grm">Guest Room</option>
                                    <option value="lby" name="lby">Lobby</option>
                                    <option value="bth" name="bth">Bathroom</option>
                                    <option value="rst" name="rst">Resturant</option>
                                    <option value="ktc" name="ktc">Kitchen</option>
                                    <option value="pol" name="pol">Pool</option>
                                </optgroup>
                                <optgroup label="Other">
                                    <option value="msc" name="msc">Miscellaneous</option>
                                </optgroup>
                            </select>

您想要获得一个$_POST变量,所以使用$_POST['roomType']来检索它。请注意错误的数据,您应该验证其中是否有正确的值。

就像@BeaverusIV所说的那样,在选择选项框中添加一个属性"value"。

<optgroup label="Main Areas">
<option value="ext" name="ext" value="Exterior">Exterior</option>
    /*.....*/
</optgroup>

选择并上传后,使用$_REQUEST['roomType']进行检索。