Jump to content

get filemtime() for file on server ?


Soledad
 Share

Recommended Posts

hello everybody as I saw filemtime() is for paths with slash "\" such as on hard disk "C:\wamp\www\"but the paths in servers with "/"when I get filemtime() for a file on hard disk it works perfect but I wanna get for a file on webserver please help me thanks .

  • Like 1
Link to comment
Share on other sites

It depends on what operating system is being used.Windows systems do accept a forward slash so I don't recommend ever using the backslash. You can use DIRECTORY_SEPARATOR so that you use the proper directory separator for the system that the script is running on. Here's an example:

filemtime('folder' . DIRECTORY_SEPARATOR . 'file.ext');

Link to comment
Share on other sites

It depends on what operating system is being used.Windows systems do accept a forward slash so I don't recommend ever using the backslash. You can use DIRECTORY_SEPARATOR so that you use the proper directory separator for the system that the script is running on. Here's an example:
filemtime('folder' . DIRECTORY_SEPARATOR . 'file.ext');

sorry but I didn't understand !!!the file in on the server how to apply this ??for example the file link is : http://localhost/ebooks/pdf/file.pdfif I used
filemtime('http://localhost/ebooks/pdf' . DIRECTORY_SEPARATOR . 'file.pdf');

it'll send an error because :http://localhost/ebooks/pdf\file.pdf

Link to comment
Share on other sites

You should use repative paths. The HTTP protocol only uses forward slashes, but it's usually not a good idea to use http to access local files.A relative path is relative to the current directory. This would work if the current PHP script is directly under localhost.

filemtime('ebooks' . DIRECTORY_SEPARATOR . 'pdf' . DIRECTORY_SEPARATOR . 'file.pdf');

Link to comment
Share on other sites

sorry my friend but it didn't work again I just gave an example for localhost but the files I wanna check are on many servers i.e : I have this file I wanna check its filemtime :http://www.damascusuniversity.edu.sy/grade..._1298367384.pdfso I set :

echo filemtime('www.damascusuniversity.edu.sy'.DIRECTORY_SEPARATOR.'grades'.DIRECTORY_SEPARATOR.'civil'.DIRECTORY_SEPARATOR.'F_1_1298367370.pdf')

but also failed :)

Link to comment
Share on other sites

If you're using the HTTP protocol you shouldn't use the directory separator, and be sure to append http:// to the URL.This function will only work if your server is configured to allow access to remote files from PHP.

filemtime('http://example.com/folder/file.ext');

Link to comment
Share on other sites

nm

Edited by birbal
Link to comment
Share on other sites

wellI did this :

$url = 'http://www.damascusuniversity.edu.sy/grades/civil/F_1_1298367384.pdf';print_r(get_headers($url));

but the date and time aren't for the file and changing each refreshlike this :Array ( [0] => HTTP/1.1 200 OK [Date] => Sat, 09 Jul 2011 20:21:23 GMT [server] => Apache/2.2.0 (Fedora) [Last-Modified] => Tue, 22 Feb 2011 09:36:24 GMT [ETag] => "482a76-2f7f6-49cdbb6b61600" [Accept-Ranges] => bytes [Content-Type] => application/pdf [Content-Length] => 194550 [Connection] => close [Age] => 194230 )Array ( [0] => HTTP/1.1 200 OK [Date] => Sun, 10 Jul 2011 11:39:38 GMT [server] => Apache/2.2.0 (Fedora) [Last-Modified] => Tue, 22 Feb 2011 09:36:24 GMT [ETag] => "482a76-2f7f6-49cdbb6b61600" [Accept-Ranges] => bytes [Content-Type] => application/pdf [Content-Length] => 194550 [Connection] => close [Age] => 139483 )please help me to do this .. :)

Link to comment
Share on other sites

  • 1 month later...

Store it in a variable, and go from there. Also, use quotes around the key, or you're otherwise asking for an element, who's key is the value of a constant of that name.In code...

$headers = get_headers($url);print_r($headers['Date']);

Link to comment
Share on other sites

P.S. as JSG said you want the "Last-Modified" header:

$headers = get_headers($url);print_r($headers['Last-Modified']);

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...