Jump to content

Check for files


kney

Recommended Posts

Hi,

 

Here's my problem:

 

The first 5 or 10 tries it should say "file not found".

After the 10th try it should automatically say "file found".

BUT it should also time out after like 50 tries and it hasn't found the file.

But i don't know how to do this..

 

I currently have this code:

 

<?php

function respond_xml($status, $message)
{
    $out = new XMLWriter();
    $out->openURI("php://output");
    $out->setIndent(true);

    $out->startDocument("1.0", "ISO-8859-1");

    $out->startElement("statuscheck");
    $out->writeElement("status", $status);
    $out->writeElement("message", $message);
    $out->endElement();

    $out->endDocument();
    
    $out->flush();
}

function main()
{
    header("Content-type: text/xml");

    if (!isset($_GET["file"]))
        respond_xml("ERROR", "File parameter missing");
    else if (file_exists($_GET["file"]))
            respond_xml("OK", "File exists");
    else
           respond_xml("NOT OK", "File does not exist");
}

main();

?>

 

This code works and gives a correct XML response when you type in for example "http://localhost:8080/php/script.php?file=test" it's says:

<statuscheck>
<status>NOT OK</status>
<message>File does not exist</message>
</statuscheck>

 

Now, I need it to be able to check it every 5 seconds so i've use this code

header("Refresh: 5; URL=http://localhost:8080/php/script.php?file=test");

Link to comment
https://forums.phpfreaks.com/topic/234328-check-for-files/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.