The File Info Extension
Fileinfo is a PHP script that you can use from your Ajax application to get
essential informations about a file on the server or any website:
- The date.
- The size.
- The type.
The XMLHttpRequest object has a similar function, getResponseHeader but it
depends upon the configuration of the server and often doesn't return what
you expect from it.
How it works
The PHP script currently holds a single function, fileinfo, with an argument:
the name of a file or a URL.
The function makes use of some PHP functions (compatible with version 4 and
5) to get the infos:
- filemtime() to get the date, and date() to format it;
- filesize() for the size of the file;
- filetype that returns these strings: file, dir, link, unknow, etc.
These infos are packed into an array with these keys in order: date, size,
type et this array is returned by the function.
To use the function, call it with a such code:
include_once("fileinfo.php");
$x = fileinfo("someurl.html");
print_r($x);
But at the same type, these infos are stored into a file in the current
directory, fileinfo.txt, each info on a line.
You can make a POST request to call the PHP script, with the filename as parameter,
followed by a GET request to retrieve the fileinfo.txt file.
Exemple of fileinfo.txt
Thu, 28 Jun 2007 19:37:18 GMT 1575 file
View this text file.
View the PHP extension (renamed
fileinfo-php.txt).
Demos
Try the demo.
This demo uses a PHP web page with all the scripts embedded into it.
Ajax version.
This demo makes use of the Anaa framework in a first step to execute the PHP
script with a POST command, and then to retrieve the results with a GET command.
