1

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>
torrentalle
  • 643
  • 4
  • 10
UserX
  • 1,295
  • 7
  • 25
  • 39

6 Answers6

3

This seems to be cache problem :

Find CACHE folder in your Theme and change CHMOD of index.html & index.php in cache folder to 755. This is what fix my problem with TimThumb.php. (If nothing happens, change it to 777, it works 100%) Source :http://wordpress.org/support/topic/timthumbphp-does-not-working-solved

If the above solution doesn't work , try following these two steps .

The first thing you need to do is ensure that your site is using the latest version of TimThumb. The easiest way to do this is to log into the WordPress dashboard, click on Appearance in the left pane, and then select timthumb.php in the right pane from the list of files. The contents of this file will appear in the center editing area. You’ll need to replace everything (yes, everything) with the code located on this page: http://timthumb.googlecode.com/svn/trunk/timthumb.php – You can do this by copy-pasta – don’t forget to save when you are done.

Now, that might resolve the problem, but if not, you will need to complete this next step, which is a bit more technical, and it might be best to ask your web designer or someone in the know, to do it for you. Locate the .htaccess file on your server, download a copy and open it up for editing. You will need to add the following 4 lines of code into the file, then save the file and upload/replace the version on your server:

<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule&amp>

Source:http://www.efrogthemes.com/tips-and-tricks/timthumb-not-displaying-images-lets-fix-that/

Sasi
  • 127
  • 6
  • Sasi, thank you for trying to help, I try your two solutions, I just dont try your last one solution yet. But your first two solutions didnt work. And Im not using wordpress and I already had last version, the same that you send me. I also think that is a cache problem, but timThumb is already working, only dont updates if I dont update also my title of news.. – UserX Jun 26 '14 at 15:01
  • 1
    I m not very sure , but try this :Remove the "Content-Length" from the header produced by timthumb . – Sasi Jun 27 '14 at 06:18
3

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) .'/>';
Raouf Athar
  • 1,803
  • 2
  • 16
  • 30
3

Simply add the file modification time to the href as a url parameter. This way you will not lose cache and the image is always updated.

$file='../uploads/images/'.$result['thumb'];
echo '<a href="'.$file.'?'.filemtime($file).'" rel="shadowbox">See actual image</a>';
torrentalle
  • 643
  • 4
  • 10
2

you can try by calling the function cleanCache() while updating the records so that cache will be rebuilt with the new image

Vijayaragavendran
  • 726
  • 1
  • 10
  • 21
2

You might need to prevent browser caching with something similar to:

    header("Expires: Wed, 1 Jan 1997 00:00:00 GMT");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");

Try to put this in your tim.php,before you send your thumbnails to browser.

Lewis
  • 14,132
  • 12
  • 66
  • 87
2

Try this on that page

header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Content-Type: application/xml; charset=utf-8");

This way you won't cache that specific page, and it should solve your problem.

Marko Vasic
  • 690
  • 9
  • 27