Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exec("touch"); Not running in PHP

Tags:

linux

php

unix

exec

I need to modify the file date change using my php script. At my localhost, I used XAMPP running in Windows 7. I had no problem using PHP touch and is working properly as I want it to be.

Yet, when I uploaded it to my production, LINUX OS the PHP touch is not working anymore. I investigated it and found that, Linux, doesn't allow PHP touch or doesn't allow anybody to change file mod date.

That's why I use exec("touch filename.txt") instead and it working properly, but when I use this code

exec("touch -t 201204040000.00 filename.txt");

It doesn't do what it must, am I missing something here?

These are my references:

  • Linux / Unix Command: touch
  • 3 UNIX / Linux touch Command Examples

EDIT

ls -l filename.txt
-rw-r--r-- 1 2012-11-04 12:00 filename.txt //supposed that 2012-11-04 12:00 is the original mod date of the file

If i run this code:

exec("touch filename.txt");
ls -l filename.txt
-rw-r--r-- 1 2012-11-05 11:00 filename.txt //supposed that 2012-11-05 11:00 is the current timestamp

The above code is working properly on me as everyone see. But if i run it like this:

exec("touch -t 201204040000.00 filename.txt");
ls -l filename.txt
-rw-r--r-- 1 2012-11-05 11:00 filename.txt //The mod date doesn't changed at all.
like image 753
sephoy08 Avatar asked Jun 11 '26 20:06

sephoy08


1 Answers

I ran your command and it does exactly what it's supposed to do:

php -r 'exec("touch -t 201204040000.00 filename.txt");'
ls -l filename.txt
-rw-r--r-- 1 2012-04-04 00:00 filename.txt

maybe if you tell us what you expect we can help you more.

like image 75
iabdalkader Avatar answered Jun 14 '26 09:06

iabdalkader



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!