gpt4 book ai didi

php - 文件类型输入不在循环中

转载 作者:行者123 更新时间:2023-11-28 16:27:20 25 4
gpt4 key购买 nike

我正在尝试上传图片并在名为 images 的文件夹中创建它的副本,但它在循环过程中不起作用,你能帮我解决这个问题吗?这是我的代码;

$sql="SELECT * FROM product";
$q=$conn->query($sql);
while($r=$q->fetch(PDO::FETCH_ASSOC))
{
$code= $r['prod_code'];
<table class="table" width=200% >
<tr>
<th colspan=6 style="background-color: lightgray"> </th>
</tr>
<tr>
<th>Add variant </th>
</tr>
<tr>
<th>Image</th>
<th>color</th>
<th>Size</th>
<th>Size Type</th>
<th>Quantity</th>
<th>Action</th>
</tr>
<tr>
<td><input type="file" name="image" id="image" style="width: 80px" required /></td>
<form method="POST">
<td><input type="text" name="addcolor" class="form-control" style="width: 150px; border-radius: 0px" required/></td>
<td><input type="text" name="addsize" class="form-control" style="width: 150px; border-radius: 0px " required/></td>
<td><select name="addtype" class="form-control" style="width: 150px; border-radius: 0px" required ><option value="International">International </option>
<option value="US">US </option>
<option value="UK">UK</option>
</select></td>
<td><input type="text" name="addquantity" class="form-control" style="width: 150px; border-radius: 0px" required/></td>
<td><button type="submit" class="btn btn-success" name="addprod" value="<?php echo $code; ?>" ><span class="glyphicon glyphicon-ok" aria-hidden="true"></span></button></td>
</form>
</tr>

</table>
}

继承人的PHP:

if(isset($_POST['addprod'])){

$prodcode= $_POST['addprod'];
$color= $_POST['addcolor'];
$size= $_POST['addsize'];
$type= $_POST['addtype'];
$quantity= $_POST['addquantity'];

$image=addslashes(file_get_contents($_FILES['image']['tmp_name']));
$image_name=addslashes($_FILES['image']['name']);
$image_size=getimagesize($_FILES['image']['tmp_name']);
move_uploaded_file($_FILES['image']['tmp_name'],"images/".$_FILES['image']['name']);
$location="images/".$_FILES['image']['name'];

$sql7 = "INSERT into color_variation (prod_code,color_pic,color,size,size_type,quantity) values('$prodcode','$location','$color','$size','$type','$quantity')";
$q7 = $conn->query($sql7);
}

它只会保存文件夹的名称和一个斜杠,并且会产生错误。请帮帮我

最佳答案

你的第一段代码有错误,我修复了它,它看起来像这样。我还更改了输入的名称(从 addcoloraddcolor[]),以便在您的第二段代码中像使用数组一样使用它们(参见如何 work with multi-dimensional array post here):

<?php

$sql = "SELECT * FROM product";
$q = $conn->query($sql);
while ($r = $q->fetch(PDO::FETCH_ASSOC)) {
$code = $r['prod_code']; ?>
<table class="table" width=200%>
<tr>
<th colspan=6 style="background-color: lightgray"></th>
</tr>
<tr>
<th>Add variant</th>
</tr>
<tr>
<th>Image</th>
<th>color</th>
<th>Size</th>
<th>Size Type</th>
<th>Quantity</th>
<th>Action</th>
</tr>
<tr>
<td><input type="file" name="image[]" id="image" style="width: 80px" required/></td>
<form method="POST">
<td><input type="text" name="addcolor[]" class="form-control" style="width: 150px; border-radius: 0px"
required/></td>
<td><input type="text" name="addsize[]" class="form-control" style="width: 150px; border-radius: 0px "
required/></td>
<td><select name="addtype[]" class="form-control" style="width: 150px; border-radius: 0px" required>
<option value="International">International</option>
<option value="US">US</option>
<option value="UK">UK</option>
</select></td>
<td><input type="text" name="addquantity[]" class="form-control" style="width: 150px; border-radius: 0px"
required/></td>
<td>
<button type="submit" class="btn btn-success" name="addprod[]" value="<?php echo $code; ?>"><span
class="glyphicon glyphicon-ok" aria-hidden="true"></span></button>
</td>
</form>
</tr>

</table>
<?php } ?>

关于php - 文件类型输入不在循环中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35871398/

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