#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    45
    Rep Power
    3

    File Upload and Sessions


    Hello,

    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!
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    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.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  4. #3
  5. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    4
    Rep Power
    0
    Originally Posted by vero
    Hello,

    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!

    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 08:16 AM.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    45
    Rep Power
    3
    Originally Posted by E-Oreo
    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.
    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?
  8. #5
  9. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,112
    Rep Power
    487
    Originally Posted by vero
    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?
    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:-

    PHP Code:
    session_start();
    echo 
    $_SESSION['myvalue']++; 
    .. 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

IMN logo majestic logo threadwatch logo seochat tools logo