ive been commissioned to create a website, but one of the requirements is driving me insane.
I have to create (or find) a php based script, that allows a user to login to the domain, upload a html file (+ images or audio files) and also specify the date, at which time the html page will be made accessible? eg. This is to allow the user to upload multiple files before going on a holiday, so that they are automatically released on the correct upload days without user interaction with the domain.
There is a good chance I will have to hit a mysql database at the same time for search indexing with ajax once the page is made available.
I have an idea how to create the php script, 'upload files to tmp dir' but im not sure how to issue a command to move them into the correct directories afterwards based on date/time. please advise.
The server will be either Ubuntu-Server or CentOS based.
I will assume that:
1. every user has a specific folder;
2. in a database will be at least a record with user and date/time to be alive;
You can do it like this:
When the user uploads the files you could move it immediatelly to his folder.
If it is the first file submited, create inside the user's folder a file index.php which will check to see if the requested time is grater than the record from the database. If yes, redirect the browser to the html file (or something else).
Make sure that the file uploaded by the user is not named index.php. If yes, rename his file something else and in your generated index make the redirection to the new name.
If your server supports cron, you could set up a short bash script to copy a list of files (as arguments) to the directory.
Alternatively, if the site is going to be getting regular hits, it may be simpler to have a PHP function that checks whether any files need copying every time the page is accessed. For speed and simplicity you could have it just check when the last copy was, and if it's more than 24 hours do the more complex stuff like checking the list of files and moving them.
EDIT: I forgot to mention (I'm not sure how much experience you've had, so apologies if this is obvious!), when you upload the files, you'd want to store something in the database like "file, date_to_move, completed", where file is the filename, date_to_move would be the mysql timestamp of the date to move and completed is a boolean so you can cut down you potential query results, i.e:
SELECT * FROM my_table WHERE CURRENT_TIMESTAMP() > date_to_move AND completed = 0
You would then update the table upon the successful move so that any moved files had completed = 1.