Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Feb 2004
    Location
    Malaysia
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy session accepting/using/storing

    hi everone,
    eer...i really don't really know how to put this but here goes anyway...i am not good at all with sessions. not totally don't know about it but just somewhere there only..now, i have a page that needs to use sessions after the user log's in. now in that page, there are 30 images that needs to be uploaded. each has different names so it's not possible to loop it..right?ok now the prob is...how do i upload 30 pictures and also identify those 30 images that it belongs to the person that whoever signs-in?get what i mean? ok here is an example:

    now lets say u have signed up in my webpage and have an account. nw u log in and u wanna upload ur 30 images. so how do i identify those 30 images belongs to you?and not other users when it goes into the database??like let's say me(mivec)once uploaded the images..how do i identify those 30 images belongs to me so it goes in as sets of 30's into the database?
    that means i would be needing sessions to identify my nick(as i am using it as a unique value) so that i can insert to the database and identify my set of 30 images.and i dunno how to do this. can any of u experts help me pls?i am going nutz thinking about this as i am no good in sessions. pls help as i am desperately in need of it. thanking you all in advance.
    Warm Regards,
    Mivec

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i don't udestand he problem.

    When you upload,you'll have a form with 30 filefields. You can name these fields whatever you want. So you could give tham all the same name + a sequencenumber like raf1, raf2, raf3 etc

    This way, you can process then in a loop
    PHP Code:
    foreach($_POST as $var=>$value){
       if ((
    substr($var03)=='raf') and (strlen($value)>=1)){
          
    your code
       
    }

    and to build them, you can just use a loop as well.

    like
    PHP Code:
    for ($i=1;$1<=30;$i++){
       echo 
    '...name="'$nick $i ." ...

    The nickname can then be selected from the db or so an stored inside a sessionvar like

    PHP Code:
    // at the top of your page
    session_start();
    ...  
    // other code including nick-selection 
    $_SESSION['nick']=$nick
    Note: using the nick as the unique identificationcriteria is probably not the best way to go. Don't you have a user-table or so with a primary key?
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #3
    Regular Coder
    Join Date
    Feb 2004
    Location
    Malaysia
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks raf for the reply and sorry for this tremendously late reply...errmm.....i dun really understand what u were trying to tell me but u said this:

    PHP Code:
    // at the top of your page 
    session_start(); 
    ...  
    // other code including nick-selection 
    $_SESSION['nick']=$nick
    errmm...if i am not mistaken..this part goes to the page that u are inputing ur username and password right?ok....so now, how do i keep my username that i have typed, check it with the db and then set the username into a session variable so that i can use this session variable to insert the username to the DB next time?

    i hope u get what i mean raf?...or anyone else has a suggestion?
    Warm Regards,
    Mivec

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    These to lines are needed to store the nickname into the sessionvariable. If you place these in the file that your formposts to, then i'd look like
    PHP Code:
    session_start();  
    ...  
    // other code including nick-selection 
    $_SESSION['nick']=$_POST['nick']; 
    If you want to retrieve the value on other pages, then you need
    PHP Code:
    session_start();  
    ...  
    // other code including nick-selection 
    $nick $_SESSION['nick']; 
    For instance, to insert it to the db
    PHP Code:
    session_start();  
    ...  
    // other code  
    $sql="INSERT INTO table (var1, var2, nickname) values (1, 'test', '" $_SESSION['nick'] . "')"); 
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #5
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,077
    Thanks
    11
    Thanked 98 Times in 96 Posts
    in otherwords , whenever/however your user logs in you at that time set a session variable with at least the username (I prefer to work with the user_id)

    then in any page that requires some knowledge of the user (or requires them to be logged in)

    session_start();

    now you have $_SESSION['nick'] etc to play with as shown by Raf above.

    For storing the images I like to either prefix the image name with an identifer or give the user thier own image directory , e.g. for an identifier..

    PHP Code:
    <?
    if(is_uploaded_file($_FILES['fieldname']['tmp_name'])){
       
    copy
         
    $_FILES['fieldname']['tpm_name'] ,
         
    './img/upload/'.$_SESSION['username'].'_'.$_FILES['fieldname']['name']
       );
    }
    ?>
    so user `jimbo` 's image called tree.jpg is now stored as /img/upload/jimbo_tree.jpg etc

    that , or copy to /img/upload/'.$_SESSION['username'].'/'.$_FILES['fieldname']['name']

    (/img/upload/jimbo/tree.jpg)


    etc , whether and how you log info about these images in the DB is another matter, I like this system as you dont need to rely on the DB for getting information about the images since thier location is logical.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #6
    Regular Coder
    Join Date
    Feb 2004
    Location
    Malaysia
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts
    oh...thank you guys...i will try to see if i can put it into my code...thanks once again.

    by the way, u see,when i upload these images, i wanna store the picture number to it as it is uploaded one by one.

    lets say, i have uploaded this image: mivec_tree.jpg and it's in the path img/userpics/mivec_tree.jpg. so in the database, there will be another field pic_Num to store the number of the picture once it is uploaded. the thing is, how can i check it from the database where the user has stopped?what i mean is that lets say if the user uploaded 5 pictures today.so the pic_num goes up to 5 right?and then the next day, he uploads another 10 pics. so how can i detect it that the first picture that he uploads on the next day starts at 6?also, how can i limit the user from uploading pics not more than 30?
    i hope u guys can understand me..thanks in advance.
    Warm Regards,
    Mivec


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •