URL で渡すニュースの ID に基づいてニュースを更新できる、news-edit.php ファイルを作成しています。
私のフォームには、フォームを送信して成功メッセージ「更新成功」を受け取った後に、入力ファイルで送信された画像を表示する div があります。
問題は、ニュースを更新すると、この div に表示されている画像が更新されないことです。フォルダー内の画像は更新されますが、ページの画像はまだ古い画像です。
なぜこれが起こっているのか分かりますか?
この div にも<a href>
リンクがあり、このリンクには rel="shadowbox" があり、このリンクをクリックすると、常に最後の画像が更新されるためです。そして、私は私のimgと私のリンクに同じパスを持っています。
唯一の違いは、私の画像では tim.php を使用してサムを生成することです。画像を表示するために tim.php を使用しない場合は正常に動作します...
そして、ニュースの画像だけでなくニュースのタイトルも更新すると、正常に機能し、divで最後の画像が更新されます。
これは私のphpです:
//first I have a list of news and each news have a link where I pass id of news in a variable &newsid
$newsid = $_GET['newsid'];
//then I read my news to see if that id of news exist
$read = $pdo->prepare("SELECT * from news WHERE id_news = ?");
$read->bindParam(1, $newsid, PDO::PARAM_INT);
$read->execute();
$result = $read->fetch(PDO::FETCH_ASSOC);
//if dont exist I show an error message
if(!$read->rowCount() >=1){
echo 'The News that you are trying to update dont exists.';
}
//then I store my post variables when my form was submited
if(isset($_POST['sendForm'])){
$f['title'] = $_POST['title'];
//if user sends an image in my input file I will upload to my folder
if(!empty($_FILES['img']['tmp_name'])){
$folder = '../uploads/images/';
$img = $_FILES['img'];
$ext = substr($img['name'],-3);
$name = $f['title'];
$f['img'] = $name.'.'.$ext;
uploadImage($img['tmp_name'], $name.'.'.$ext, '300', $folder);
}
//I do my update
$updNot = $pdo->prepare("UPDATE news set thumb =?, title=? WHERE id_news = ?");
$updNot->bindParam(1,$f['img']);
$updNot->bindParam(2,$f['title']);
$updNot->bindParam(3,$newsid);
$updNot->execute();
echo 'sucess updating';
}
これは私のフォームです:
<form method="post" enctype="multipart/form-data">
<div>
<span>Title</span>
<input type="text" name="title"/>
</div>
<!--this is my div where I show my last updated image and where I have my input file-->
<div>
<span>Image:</span>
<input type="file" name="img" accept="image/gif, image/jpg, image/jpeg, image/png" />
<?php
echo '<div>';
echo '<img src="../tim.php?src=../uploads/images/'.$result['thumb'].'&w=50&h=45&q=100&zc=1"/>';
echo '<a href="../uploads/images/'.$result['thumb'].'" rel="shadowbox">See actual image</a>';
echo '</div><!--actual_image-->';
?>
</div>
<input type="submit" title="Update" value="Update" name="sendForm"/>
</form>