1

I am trying to get the date in which a file was modified or created with PHP. To do this I am using filectime function but it is giving me always the following error:

Warning: filectime(): stat failed for path

where path is the route in which I have stored the file.

The route is something similar to this:

http://MYIP/documents/animals document 1.pdf
http://MYIP/documents/animals document 2.pdf
...

and I have to replace the url to codify the spaces of the file:

$path= str_replace(' ', '%20', $path);

If I do this I can use a link to open this file on my browser but it shows the warning that I have put before if I try to use the same path on filectime function.

Am I missing something?

Thanks in advance!

Punit Gajjar
  • 4,937
  • 7
  • 35
  • 70
Francisco Romero
  • 12,787
  • 22
  • 92
  • 167
  • http://php.net/manual/en/wrappers.http.php: _“Supports stat(): No”_ – you simply can not use this for HTTP URLs. – CBroe Feb 14 '17 at 13:30
  • 1
    _“I am trying to get the date in which a file was modified or created with PHP”_ – so use a file system path, not an HTTP URL. – CBroe Feb 14 '17 at 13:30

1 Answers1

1

The filectime function expects a string path as a parameter. It is just a wrapper function over the usage of Posix stat system call.

The system call:

int stat(const char *pathname, struct stat *buf);

So, it expects a parameter as though it's on your filesystem. The URL gets encoded to have a neat white-space-less identifier on the server side to execute appropriate scripts.

Don't bother with that "codification"! Just use a standard string path as you'd use on your UNIX shell, relative to the script directory.

In this case, just provide the right path to the PHP function!

filectime("documents/animals document 2.pdf");
varun
  • 2,027
  • 1
  • 15
  • 17
  • 1
    _“You need escape sequences for the white spaces in the path”_ – no you don’t, not in the file system. – CBroe Feb 14 '17 at 13:28
  • @CBroe Ah! Yup, you're right! Thanks for the correction! I was still in the context of the UNIX shell while typing that sentence... :P – varun Feb 14 '17 at 13:47
  • @varun But the IP is mine but external so I had to access the file with the path: `IP/animals/animals document 2.pdf`. – Francisco Romero Feb 14 '17 at 15:23
  • @varun Finally I downloaded all files to my local network to have access to them using `filectime` function. I could not find any way using remote http path. – Francisco Romero Feb 14 '17 at 16:05