Jump to content

How To Change A File Date?


TheCanadian

Recommended Posts

I have a script which loads a list of PDF newsletters in a directory and displays them according to the date they were originally uploaded. Unfortunately, on occassion I need to fix a goofed up file and reupload, which now updates the modified date and goofs up the order of the newletters. I need to be able to change the date on the file to put it back in the right order. The files are uploaded by me via FTP, so they are set to my user and not "nobody". I have tried setting the chmod to 666 and using the PHP touch command, but it tells me I'm not allowed to perform that function.

How can I do this?

Link to comment
Share on other sites

The documents are named by date, but not a numerical date (eg. "November 2007 Gazette.pdf" or "Summer 2008 Meeting.pdf") so there is no way of showing them in the correct order. Changing all the filenames to something like "2007-11 Gazette.pdf" is not an option. Is there any way to change the date of an uploaded file? Through FTP maybe? Perhaps some way to run a Unix touch command under my user id instead of the "nobody" user through cpanel somewhere?

 

UPDATE: Found a simple solution! Since the problem was that the file was my user and the PHP touch command executed from the web runs as user "nobody", I tried uploading the file through a PHP script instead of FTP. So now my "nobody" script has the permission to modify my "nobody" file. Sweet! That will work!

Edited by TheCanadian
Link to comment
Share on other sites

That seems like a slightly insecure method of doing it. Setting your file to nobody and 777 means that is could potentially be modified by an external source.

 

I have just checked and using SmartFTP you can change the modified and created dates of an uploaded file... try looking into getting SmartFTP - there is a 30 day trial, but it costs for the full version, however I think it was worth it.

Link to comment
Share on other sites

Color me stupid. The *nix touch command with the -t flag allows you to modify the dates. Should have looked up the man page before answering.

 

I tried it by using PHP to run the command:

>exec("touch -t 200711010000.00 'November 2007.pdf'")

but it didn't seem to do anything. I think the issue of the PHP script running as "nobody" is the problem again. My account doesn't have SSH access so I can't login to run the command directly. I think I'd pretty much need a way to run a command under my user instead of the nobody user.

 

OJB: SmartFTP must be using an FTP command to do that. Do you know what command it is? I can run custom commands with my FTP client. I tried

>MDTM 20071101000000 "November 2007.pdf"

but it gave me an error: "Can't check for file existence", so I assumed the TCH FTP server I'm on doesn't support using MDTM to change the file date. I can't find another FTP command that is designed to do that.

Link to comment
Share on other sites

Oh!! I'm getting somewhere! I checked and the server is using Pro-FTPd. HELP says it supports SITE UTIME. Docs for Pro-FTPd says this is used to modify the file dates. So I looked up how to use SITE UTIME, and found:

http://www.proftpd.org/docs/contrib/mod_si...html#SITE_UTIME

 

So I tried:

>SITE UTIME 200711010000 "November 2007.pdf"

And I get a response of "500 UTC Only". So I'm getting close, just missing something I think.

 

UPDATE: Got it!!!

 

Man, this took some heavy Googling... I found that some implementations of SITE UTIME work totally differently, letting you change the creation date, modification date and access date. So I tried changing the command:

>SITE UTIME November 2007.pdf 20071101000000 20080211000000 20080211000000 UTC

And holy crap, it worked! I also had to remove the quotes because it didn't work with them (they weren't needed).

Edited by TheCanadian
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...