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

    Join Date
    Apr 2004
    Posts
    5
    Rep Power
    0

    How to let users apply a .css file via a dropdown menu? w/ or w/o using a database?


    Hey!

    I would like to write a script that allows users to select .css files from a pulldown menu that is populated by all the .css files located in a given directory. The goal is to "write" the selected file's name into a config file (I assume) so that that particular .css file will be the one used. Then if the user wants to change .css files, they nav. back to the pulldown page and reselect a new .css file.

    Is this possible? I don't expect that someone will write this for me...but hopefully someone might be able to point me in the right direction...

    A feature that would allow users to upload (only) .css files would also be excellent...but I realize that would require populating the dropdown with information in my database...(thus negating the first paragraph...)

    Which method would be better? And how can I go about writing the pulldown selection to a config file?

    Your wisdom is much appreciated.

    Thank you.

    Cranjled

    PS. If doing this with PHP is not the right way...please don't hesitate to tell me! I only assumed php since my site is in php...
  2. #2
  3. mod_dev_shed
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    14,817
    Rep Power
    1100
    Yes, possible.

    You have to decide if you want to give the user the upload feature before you go any further b/c this will change how you approach this. Let us know what you decide.

    As a pointer, instead of writing to a config file (b/c you'd have one per user), use a cookie to store the choice.
    # Jeremy

    Explain your problem instead of asking how to do what you decided was the solution.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Posts
    5
    Rep Power
    0
    Thanks Jeremy for the quick reply!

    I think I should clarify this... the bold sections below should clear it up...

    I would like to write a script that allows me to select .css files from a pulldown menu that is populated by all the .css files located in a given directory. The goal is to "write" the selected file's name into a config file (I assume) so that that particular .css file will be the one used when (all) users view the site. Then if I wanted to change .css file, I'd nav. back to the pulldown page and reselect a new .css file. This change would then be viewed by any users on the site.

    A feature that would allow only me to upload (only) .css files would also be excellent...but I realize that would require populating the dropdown with information in my database...(thus negating the first paragraph...)

    ...and yes, I'd much like to be able to upload the css files via browser, instead of FTPing them in.

    Thanks again for your reply!
    Last edited by cranjled; April 10th, 2004 at 04:00 PM.
  6. #4
  7. Trapped on the forums...help
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2003
    Location
    /Users/edman007
    Posts
    4,617
    Rep Power
    906
    you can just set up a folder has all the css files you will use, and a script to upload extra css file to there, just read the contents of the directory to get a list of all css files, when you select one copy to the one that is in use by the site overwriting the old one
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Posts
    5
    Rep Power
    0
    Yes, I understand that it could be done this way...this is how I'm doing it now...but that method is a bit primitive since it requires copy and paste and FTP. What I'd prefer to do is to have a pulldown menu automatically update with all the files in the directory and to automatically apply itself via a pulldown menu selection. The main thing is that it's browser based...and on the fly.

    Thanks for your suggestion!
  10. #6
  11. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Location
    Japan/NZ
    Posts
    105
    Rep Power
    13
    I think what edman007 mean't was using PHP to do exactly what you are doing manually.
    It's a little bit messy but basically you'd have two directories - something like:
    css_all
    css_current
    First your script would look in css_current to find the current css file - place the name of this in a variable. Then open the css_all folder and loop through the contents to populate a select menu - using the variable to match the current file from the select menu.
    When you select a different file from the select menu and submit, the previous file in css_current is deleted and replaced with the one you have chosen.
    All the functions you need are in the Filesystem functions section of the PHP manual.
    ______________ m(_ _)m ______________

    fusionbureau design studio - design and stuff in tokyo
  12. #7
  13. Trapped on the forums...help
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2003
    Location
    /Users/edman007
    Posts
    4,617
    Rep Power
    906
    yes that is what i'm saying to do but in php, make a form to upload it, this is what the html would look like

    Code:
    <form action="upload_css.php" method="POST"  enctype="multipart/form-data" >
    <input type="file" name="css" size="50" />
    </form>
    then the php in upload_css.php would have this

    PHP Code:
    <?php
    move_uploaded_file
    ($_FILES['css']['tmp_name'], '/path/to/css/storage/folder/'.$_FILES['css']['name']);
    ?>
    and this would change the css being used

    PHP Code:
    <form action="change_css.php" method="POST">
    <select name="css">
    <?php
    while (false !==($file readdir('/path/to/css/storage/folder/'))){
    if (
    $file != '.' && $file != '..'){
    echo 
    "<option value=\"$file\">$file</option>";
    }
    }
    ?>
    </select>
    </form>
    then the file change_css.php would have this

    PHP Code:
    copy('/path/to/css/storage/folder/'.$_POST['css'], '/path/to/site/wide/css/file.css'); 
    of course you will have to add lots of error checking and security stuff but i hope you get the idea
    Last edited by edman007; April 10th, 2004 at 08:17 PM. Reason: typo
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Posts
    5
    Rep Power
    0
    Thank you, thank you!! Yes, in fact I finally get the idea...that I've bitten off more than I can chew. Ah well...maybe next year... thank you guys for being there.

    Don't mind me as I slink back to my corner...
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Posts
    5
    Rep Power
    0
    (that's not to say that I'm not going to try!)

IMN logo majestic logo threadwatch logo seochat tools logo