开发者

Creating Temporary Filepage in Php - Possible? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 9 years ago.

Improve this question 开发者_开发技巧

I was wondering if it's possible to use php to create a file with a specific name that would last 30 seconds, and then delete its self. I looked at the tmpfile and tmpnme functions but I must not know how to use them correctly.

I would like to click a button on webpage A, and then have information shown on webpage B for 30 seconds. Once the 30 seconds is up, the information would change or clear out entirely.

Possible?


PHP can easily create a temporary file for you, but it'll be up to you to actually remove it after the 30 seconds is up. PHP isn't a scheduler, though it can schedule things for you via cron or at.

Your best bet would be to embed some extra code into the PHP script as it's built to specify an expiry time, which the generated script can check when it's first started:

<?php

$expires = ...insert some timestamp value here...;

if ($expires < time()) {
    unlink(__FILE__);
    header("Location: somewhere else");
    exit();
}

... do whatever you need to here ...

That'll take care of the script terminating itself. But if the script is never accessed outside of the 30 second window, it wouldn't clean itself up, so you'd still need an external job to go in and do some periodic housecleaning.


You can create a file like an XML for example. Add a new node and time stamp it. Then your website can load the file and based on the timestamp show the node that hasn't expired. You don't have to delete the file just don't show the old data. You can also when loading the node, delete the old ones to keep the file from getting large.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜