开发者

Cakephp picture upload does not update right away

When I upload a picture into my website and redirect back to the page, the picture does not update until you refresh the page a few times. I assume the browser is showing the previous cached image. Is there a simple way in cakephp to prevent this? the form code is below:

    echo $form->create('UserImage', array('controller' => 'user_images', 'action' => 'add', 'type' => 'file'));
    echo $form->file('File');
    echo $form->submit('Upload');
开发者_C百科    echo $form->end();

Please let me know, thanks!


put a timestamp in your image url to force a refresh:

echo $html->image('image.jpg?'.time()));


If you save the image with same name than older one, browser will keep that image in cache. Like Anh Pham said, append timestamp or whatever random string to image name and it should load the new image. But, I would rather recommend save the image with different name, not just print it in view with some random string, so browser can load it from cache after first pageload.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜