October 2nd, 2012, 04:56 PM
File Upload and Sessions
I have a script that uploads a zipped folder and extracts folder to a directory. I have code that loops through the uploaded folder and run some other code. How would I prevent the uploaded folder from:
1. Being overridden by simultaneous uploads
2. Only loop through the folder that the user just uploaded not all the folders that are currently inside the directory
I'm not experienced with Sessions and not sure if this is the route to go. Any help is appreciated. Thank you!
October 4th, 2012, 10:16 PM
If the code is on separate pages you might use sessions, but that's not really clear from your description.
To prevent the files from being overridden, you would use a unique file name for it.
October 5th, 2012, 03:14 AM
Originally Posted by vero
Use the unique id function or rand function, that will increase a table column, But you get the desired result you require.
Last edited by ManiacDan; October 5th, 2012 at 09:16 AM.
October 8th, 2012, 10:56 PM
Sorry, I should've been more detailed. What I want to achieve is allow users to upload zipped folders to a directory/folder generated by PHP session. So, a new directory/folder, incremented by 1, is created everytime a user uploads a zipped folder. For example, upload001, upload002, etc.. I then want to create a cron job to delete the generated folder as well as the uploaded folder inside of it once a user downloads their files. Is this even possible?
Originally Posted by E-Oreo
October 9th, 2012, 04:15 AM
Originally Posted by vero
A $_SESSION is a variable which remains in memory until it's unset (either by the browser closing or your script unsetting it). It's very handy to use it to pass certain variables from one page to another, say for example if your site requires a login, then you can store the user level or ID in the $_SESSION variable and reference that before delivering page content to the browser (as opposed to looking up information from a database each time the page is changed to see if the currently logged in user is allowed to view the content or not).
It does NOT however, allow multiple site visitors to share the values in there.
For example, if I had this script:-
.. and browsed it in my web-browser, initially I would see nothing but then every refresh, I'd see a number 1 and then each subsequent refresh it would increment by 1 each time. If another visitor went to that web-page, they would see exactly the same, nothing then an incrementing counter starting at 1.
What you'd need to do is store the "current folder number" into a database (or text file or whatever) and then each time someone submits files, this would be incremented.
As for the CRON job, well, that's perfectly possible, just call the command-line PHP application. eg: "php /path/to/file.php".
"For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
- George Orwell, 1984