简体   繁体   中英

exec(“touch”); Not running in PHP

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:

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM