View Full Version : schedule to delete files
s00263668
07-31-2006, 02:00 AM
Hi everyone,
my server have to delete image files which were created 1 days ago. I intend to implement this feature by using "Scheduled Tasks" in windows XP, so that it can runs automatically everyday.
Here my problem come, I can't find suitable batch file(.bat) for that. Do you guys have any batch file to implement that? Or do you have other ideas without using "Scheduled Tasks"?
Thanks for help
ps: beside batch file, can we run php script automatically? I have try once but it cannot work(since we cannot use IE to execute php file directly)
djr33
07-31-2006, 09:53 AM
php can only be run when a request is sent to the server for the page.
You could add a code like this to all (or some/one) of your pages:
<?php
if ($day = "new") {
include("cleanup.php");
$day = "old";
}
Where the variable $day is set to new if the current date is "new", and not "old". In a practical example, you'd compare the date to that of one stored in a database/text file (or even the creation time of a file on the server, like one of the images, IF there is one you know will always be there, or something), then check if that value is the same as that of the current date.
Then the included "cleanup.php" page would have the "delete all images" function (look at php.net, shouldn't be too hard).
Then you want to set the "day" to "old, whether by changing the value in the database, or something else.
That way, it won't run again on the next load.
OR, you could just write the cleanup.php page so it deletes anything more than 24 hours old. That's fairly easy too.
Then just include that on each page, no if needed.
s00263668
08-01-2006, 01:41 AM
thanks. The problem solved.
I have add program file of Internet Explorer into schedule, and the homepage set to file delete page.
Actually, somewhere on your server you'll probably find an executable called "php.exe". This can be used to run PHP scripts directly from the command line. Simply supply the script as an argument.
mwinter
08-01-2006, 02:07 AM
You could add a code like this to all (or some/one) of your pages:
<?php
if ($day = "new") {
include("cleanup.php");
$day = "old";
}One could, though it would add overhead to every request. As such, performing scheduled tasks like this should be avoided whenever a cron (or similar) service is available.
Actually, somewhere on your server you'll probably find an executable called "php.exe". This can be used to run PHP scripts directly from the command line.The OP should be aware that there are several PHP executables available, depending on the version of PHP installed.
In PHP 4, there is a php.exe executable in the cli subdirectory (CLI is an acronym for Command Line Interface). The php.exe executable in the root installation directory is the CGI (Common Gateway Interface) version, which intended for use with a server.
In PHP 5, the situation changes. The CGI version has been renamed php-cgi.exe, and the CLI version can now be found in the root installation directory. There's also a new php-win.exe executable which doesn't cause the console window to open.
The install.txt file contains a description of this in the Manual Installation Steps section, and the PHP manual (http://uk.php.net/manual/en/index.php) contains information about running PHP from the command line (http://uk.php.net/manual/en/features.commandline.php).
Mike
s00263668
08-01-2006, 05:13 AM
One could, though it would add overhead to every request. As such, performing scheduled tasks like this should be avoided whenever a cron (or similar) service is available.
The OP should be aware that there are several PHP executables available, depending on the version of PHP installed.
In PHP 4, there is a php.exe executable in the cli subdirectory (CLI is an acronym for Command Line Interface). The php.exe executable in the root installation directory is the CGI (Common Gateway Interface) version, which intended for use with a server.
In PHP 5, the situation changes. The CGI version has been renamed php-cgi.exe, and the CLI version can now be found in the root installation directory. There's also a new php-win.exe executable which doesn't cause the console window to open.
The install.txt file contains a description of this in the Manual Installation Steps section, and the PHP manual (http://uk.php.net/manual/en/index.php) contains information about running PHP from the command line (http://uk.php.net/manual/en/features.commandline.php).
Mike
totally lost........-.-|
Don't do it. It's slow. Use the php.exe executable instead, which can be found in root/cli in PHP4 (where root is the directory in which you installed PHP), or in the top directory in which you installed PHP for PHP5.
s00263668
08-03-2006, 05:45 PM
I once double click on php.exe but it do nothing?
can i know the dos command (or any other command) to run php script through php.exe?
mwinter
08-03-2006, 07:15 PM
I once double click on php.exe but it do nothing?The PHP executable expects command line arguments to instruct it what do to. It's not like many programs that display a user interface; it's not that sort of software.
can i know the dos command (or any other command) to run php script through php.exe?Run:
  /path/to/php -f /path/to/file
For example, I've installed PHP to D:\PHP\5.1.4, so to run a file called X:\example.php, the command would be:
  D:\PHP\5.1.4\php -f X:\example.php
Be aware that the working directory (the directory used to resolve path names like ..\dir) isn't changed by the PHP executable. You either have to:
set the directory before running the script,
use the chdir function within the script to change the directory at run-time, or
use full path names (like X:\path\to\file), avoiding the issue entirely.
Hope that helps,
Mike
s00263668
08-04-2006, 07:40 AM
thanks for help:)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.