Results 1 to 10 of 10

Thread: schedule to delete files

  1. #1
    Join Date
    Jul 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default schedule to delete files

    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)

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jul 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks. The problem solved.

    I have add program file of Internet Explorer into schedule, and the homepage set to file delete page.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by djr33
    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.


    Quote Originally Posted by Twey
    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 contains information about running PHP from the command line.

    Mike

  6. #6
    Join Date
    Jul 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by mwinter
    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 contains information about running PHP from the command line.

    Mike
    totally lost........-.-|

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Jul 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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?

  9. #9
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by s00263668
    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:

    &#160;&#160;/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:

    &#160;&#160;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

  10. #10
    Join Date
    Jul 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks for help

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •