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>
4

6 回答 6

3

这似乎是缓存问题:

在您的主题中找到 CACHE 文件夹并将缓存文件夹中 index.html 和 index.php 的 CHMOD 更改为 755。这就是解决我的 TimThumb.php 问题的方法。(如果没有任何反应,将其更改为 777,它可以 100% 工作)来源:http ://wordpress.org/support/topic/timthumbphp-does-not-working-solved

如果上述解决方案不起作用,请尝试执行以下两个步骤。

您需要做的第一件事是确保您的网站使用的是最新版本的 TimThumb。最简单的方法是登录 WordPress 仪表板,单击左窗格中的外观,然后从文件列表中选择右窗格中的 timthumb.php。该文件的内容将出现在中心编辑区域。您需要使用此页面上的代码替换所有内容(是的,所有内容):http: //timthumb.googlecode.com/svn/trunk/timthumb.php – 您可以通过复制粘贴来执行此操作 – 不要完成后忘记保存。

现在,这可能会解决问题,但如果没有,您将需要完成下一步,这会更具技术性,最好请您的网页设计师或知情人士为您完成。在您的服务器上找到 .htaccess 文件,下载一个副本并打开它进行编辑。您需要将以下 4 行代码添加到文件中,然后保存文件并上传/替换服务器上的版本:

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

资料来源:http ://www.efrogthemes.com/tips-and-tricks/timthumb-not-displaying-images-lets-fix-that/

于 2014-06-26T06:39:22.633 回答
3

只需将文件修改时间作为 url 参数添加到 href。这样您就不会丢失缓存并且图像始终会更新。

$file='../uploads/images/'.$result['thumb'];
echo '<a href="'.$file.'?'.filemtime($file).'" rel="shadowbox">See actual image</a>';
于 2014-07-02T23:10:07.550 回答
3

很久以前,我通过执行以下操作解决了这样的问题:

echo '<img src="../tim.php?src=../uploads/images/'.$result['thumb'].'&w=50&h=45&q=100&zc=1&"'. rand(99,9999) .'/>';
于 2014-07-02T05:22:44.200 回答
2

您可能需要使用类似于以下内容来防止浏览器缓存:

    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");

tim.php在将缩略图发送到浏览器之前,请尝试将其放入您的,。

于 2014-06-30T11:54:04.517 回答
2

您可以尝试 cleanCache()在更新记录时调用该函数,以便使用新图像重建缓存

于 2014-06-30T11:45:28.403 回答
2

在那个页面上试试这个

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");

这样您就不会缓存该特定页面,它应该可以解决您的问题。

于 2014-06-30T12:32:54.550 回答