Im develloping a news-edit.php file where I can update my news based on the id of the news that I pass in url.
In my form I have a div where I show image sent in my input file after I submit my form and get my sucess message 'sucess updating'.
The problem is, when I update my news, the image that is showing in this div dont update, in my folder the image is updated, but on my page the image is still my old image.
Do you see why this can be happening?
Because I have also a <a href>
link in this div, and this link have a rel="shadowbox" and When I click in this link Im always getting my last image updated.
And I have the same path on my img and on my link.
The only difference is that for my image Im using tim.php to generate thumbs, and If I dont use tim.php to show image it works fine...
And If I update not only image of news but also update title of my news it works fine, in my div I get my last image updated.
This is my 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';
}
This is my form:
<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>
Long ago I solved such a problem by doing something like this:
echo '<img src="../tim.php?src=../uploads/images/'.$result['thumb'].'&w=50&h=45&q=100&zc=1&"'. rand(99,9999) .'/>';