嗨我正在尝试使用for循环更新图像,因为我在插入时使用了它。但它只是在所有记录上更新一个值。请
<?php session_start();
require_once("SubmitController/sale_property_controller.php");
$objproperty = new sale_property_controller();
if (count($_FILES['upload']['name']) > 0) {
//Loop through each file
for ($i = 0; $i < count($_FILES['upload']['name']); $i++) {
//Get the temp file path
$tmpFilePath = $_FILES['upload']['tmp_name'][$i];
//Make sure we have a filepath
if ($tmpFilePath != "") {
//save the filename
$shortname = date('d-m-Y-H-i-s') . '-' . $_FILES['upload']['name'][$i];
//save the url and the file
$filePath = "../img/saleproperty/" . $shortname;
//Upload the file into the temp dir
if (move_uploaded_file($tmpFilePath, $filePath)) {
$_SESSION['Property_images'][] = $shortname;
}
}
}
}
if(!$_SESSION['Property_images']){}else{
foreach ($_SESSION['Property_images'] as $items => &$item ) {
$property_id=$_GET['id'];
$objproperty->Updateproimg($property_id, $item);
}
}
?>
这是我的功能
function Updateproimg($property_id, $item)
{
$sql="update images_property set images='".$item."' where property_id='".$property_id."' ";
$this->update($sql);
}
答案 0 :(得分:0)
我觉得你必须依靠伯爵($ _ FILES [&#39;上传&#39;]而不是$ _FILES [&#39;上传&#39;] [&#39;名称&#39;] ;
$count = count($_FILES['upload'])
for($i=0; $i<=$count; $i++) {
$tmpFilePath = $_FILES['upload'][$i]['tmp_name'];
}
您是否正在尝试多个文件上传?