我有问题。我正在尝试创建一个可以替换图像的系统,然后它将在数据库中发生变化。然而,我的article_pictures就像这个“image1& image2& image2”一样,所以我希望系统检查一个特定的图像是否已被更改并上传该图像并更改该字符串上的名称。
虽然它上传了图片但是字符串被替换为“(”)而不是更改值
现在我创建了以下代码,我真的希望有人得到错误的
if (isset($_POST['updateArticle']))
{
$title = $_POST['title'];
$article = $_POST['article'];
$valid_formats = array("jpg", "png", "gif", "zip", "bmp");
$max_file_size = 1024*1000; //1000 kb
$count = 0;
$articleid = $_GET['edit'];
$collectarticle = "SELECT * FROM ARTICLES WHERE article_id = '$articleid'";
$result = mysqli_query($con, $collectarticle);
if (mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_assoc($result))
{
$pictcount = $row[article_picturecount];
$pictcount2 = 0;
do
{
$picturename[$pictcount2] = $_FILES['edit_'.$count2];
$pictcount = $count - 1;
$pictcount2++;
}
while($pictcount > 0);
$pictures = explode('&' , $row[article_pictures]);
$count = $row[article_picturecount];
$count2 = 0;
do
{
if ($picturename[$count2] != "")
{
if ($pictures[$count2] != $picturename[$count2]['name'])
{
if(move_uploaded_file($_FILES["edit".$count2]["tmp_name"],"../img/uploads/".$picturename[$count2]))
{
$pictures[$count2] = $picturename[$count2];
}
else
{
echo "Er is iets misgegaan met het uploaden van picturename[".$count2."]";
die();
}
}
}
$count = $count - 1;
$count2++;
}
while($count > 0);
$count = $row[article_picturecount];
$pictcount2 = 0;
$andcount = $row[article_picturecount] - 1;
do
{
$picturenameupdate = $pictures[$count2];
if ($andcount > 0)
{
$picturenameupdate = $picturenameupdate."&";
$andcount = $andcount - 1;
}
$count = $count - 1;
$count2++;
}
while($count > 0);
}
}
$articleid = $_GET['edit'];
$database = "UPDATE ARTICLES SET article_title = '$title', article_content = '$article', article_pictures = '$picturenameupdate' WHERE article_id = '$articleid'";
if (mysqli_query($con,$database))
{
$notice = "Het artikel is aangepast!";
header('Location: http://portal.globaltowerservices.nl?notice='.$notice);
exit();
}
else
{
$notice = "Er is iets mis gegaan. Probeer het opnieuw.";
}
}
提前致谢!
答案 0 :(得分:0)
结果是:
<?
if(isset($_GET['edit']))
{
if (isset($_POST['updateArticle']))
{
$title = $_POST['title'];
$article = $_POST['article'];
$articleid = $_GET['edit'];
$collectarticle = "SELECT * FROM ARTICLES WHERE article_id = '$articleid'";
$result = mysqli_query($con, $collectarticle);
if (mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_assoc($result))
{
if ($row[article_picturecount] > 1)
{
$pictcount = $row[article_picturecount];
$pictcount2 = 0;
do
{
$name = "edit_".$pictcount2;
$picturename[$pictcount2] = $_FILES[$name]['name'];
$pictcount = $pictcount - 1;
$pictcount2++;
}
while($pictcount > 0);
}
else
{
$picturename = $_FILES['edit_1']['name'];
}
if ($row[article_picturecount] > 1)
{
$pictures = explode('&' , $row[article_pictures]);
}
else
{
$pictures = $row[article_pictures];
}
if ($row[article_picturecount] > 1)
{
$uploadcount = $row[article_picturecount];
$uploadcount2 = 0;
do
{
if ($picturename[$uploadcount2] != "")
{
if ($pictures[$uploadcount2] != $picturename[$uploadcount2]['name'])
{
$name = "edit_".$uploadcount2;
if(move_uploaded_file($_FILES[$name]["tmp_name"],"../img/uploads/".$picturename[$uploadcount2]))
{
$pictures[$uploadcount2] = $_FILES[$name]['name'];
}
else
{
echo "lol nee";
die();
}
}
}
$uploadcount = $uploadcount - 1;
$uploadcount2++;
}
while($uploadcount > 0);
}
else
{
if($pictures != $picturename)
{
if(move_uploaded_file($_FILES['edit_1']["tmp_name"],"../img/uploads/".$picturename))
{
$pictures = $picturename;
}
else
{
echo "het uploaden is niet gelukt";
}
}
}
if ($row[article_picturecount] > 1)
{
$count = $row[article_picturecount];
$count2 = 0;
$andcount = $row[article_picturecount] - 1;
$picturenameupdate = "";
do
{
if ($picturenameupdate == "")
{
$picturenameupdate = $pictures[0];
}
else
{
$picturenameupdate = $picturenameupdate.$pictures[$count2];
}
if ($andcount > 0)
{
$picturenameupdate = $picturenameupdate."&";
$andcount = $andcount - 1;
}
$count = $count - 1;
$count2++;
}
while($count > 0);
}
else
{
$picturenameupdate = $pictures;
}
}
}
$articleid = $_GET['edit'];
$database = "UPDATE ARTICLES SET article_title = '$title', article_content = '$article', article_pictures = '$picturenameupdate' WHERE article_id = '$articleid'";
if (mysqli_query($con,$database))
{
$notice = "Het artikel is aangepast!";
header('Location: http://portal.globaltowerservices.nl?notice='.$notice);
exit();
}
else
{
$notice = "Er is iets mis gegaan. Probeer het opnieuw.";
}
}
?>
这也涵盖只有一张图片的文章