Msg#: 3329451 posted 4:49 am on May 3, 2007 (gmt 0)
It turns out that opendir and a number of other cool PHP features are disabled by my host. I've had to deal with similar issues before and have worked around them (that's part of the fun.) What I am trying to do is create a PHP file which will delete specific files from a directory that are more than 24 hours old. My question is this: Is this possible without readdir and opendir? Can I use fopen and fread as alternatives in my solution? The key problem that I see is that I can read the log file but where do I begin to parse the log file into file names and dates? Typical entries in my log file would look like this:
2007/05/02 2:00:31 : File http://www.example.com/myFile.zip Sent to firstname.lastname@example.org
2007/05/02 2:08:31 : File http://www.example.com/myPic.jpg Sent to email@example.com
I guess I would have to somehow define the format of each entry? If so how would I do this. Is this idea even realistic with PHP? If anyone has any ideas or ideas about different approaches please let me know. Thanks.
Msg#: 3329451 posted 9:13 pm on May 6, 2007 (gmt 0)
Does your host allows you to use the FTP functions [php.net] of PHP? You then may use these to FTP to your server and delete the files using ftp_delete [php.net]. FTP also provides functions for reading, creating and deleting directories.
Msg#: 3329451 posted 1:22 am on May 7, 2007 (gmt 0)
I looked into all of the suggestions submitted here and each has its own merit, however, it seems that my biggest hurdle is that I won't necessarily know the names of these files to target them. I only know where they will be. Also I can't delete all of the files at once only those that are more than 24 hours old. That's why I thought in lieu of the functions not available to me because of shared server constraints (noted at the beginning of this post) I thought I could create a script to parse the information I needed from my detailed log files to identify specific files that met the criteria for deletion. I didn't glean that I could do this with the examples suggested. If I am wrong could someone elaborate on how I would apply the presented options?
Msg#: 3329451 posted 8:05 am on May 7, 2007 (gmt 0)
If I understand your posts correctly you have a log file in the format described in your first post. Is this format fixed or can you change the script that writes this logfile so it writes one entry per line in a format that can be parsed easily by another script like e.g.: 2007/05/02 2:00:31 http://www.example.com/myFile.zip firstname.lastname@example.org 2007/05/02 2:08:31 http://www.example.com/myPic.jpg email@example.com
Is this possible? If not we have to make a more complex parser to parse the logfile in the format you described.