gpt4 book ai didi

PHP PDO 多图像插入

转载 作者:行者123 更新时间:2023-11-29 00:08:06 24 4
gpt4 key购买 nike

我在这方面还很陌生,很难构建一个非常简单的图像上传脚本。我有一个名为 txtfoto 的输入文件,如果我插入一条记录这很好,但我想做的是插入 4 个名为 txtfoto[] 的输入文件的值一次。我确定我的 PHP 代码中有问题或缺失,所以我会非常乐意提供任何帮助。

HTML:

<label>Imagen: <input name="txtfoto[]"  type="file">
<input name="txtfoto[]" type="file">
<input name="txtfoto[]" type="file">
<input name="txtfoto[]" type="file"></label>

PHP:

    $file = $_FILES["txtfoto"]["name"][$key]

mysql语句:

for ($key=0; $key<count($_FILES["txtfoto"]["name"][$key]); $key++){
$sql = "INSERT INTO imagenes (nombre,foto) VALUES (:nombre,:foto)";
$result = $db->prepare($sql);
$result->execute(array(':nombre' => $txtnombre, ':foto' => $file));}
}

最佳答案

for ($key=0; $key<count($_FILES["txtfoto"]["name"]); $key++){
$file = $_FILES["txtfoto"]["name"][$key];
$sql = "INSERT INTO imagenes (nombre,foto) VALUES (:nombre,:foto)";
$result = $db->prepare($sql);
$result->execute(array(':nombre' => $txtnombre, ':foto' => $file));}

关于PHP PDO 多图像插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26571409/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com