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

    Join Date
    Apr 2013
    Posts
    7
    Rep Power
    0

    Session variable to move_uploaded_file file path


    Hi a variable hard written seems to work

    PHP Code:
    $id 5646843// <<<<
     
    $targetPath $_SERVER['DOCUMENT_ROOT']."/members/$id/$filename"
     
    move_uploaded_file($filetmpname$targetPath); 
    but a session variable does not. I have tried converting it into a string but no luck. Is there a way to fix this? I have tried searching everywhere but I couldn't find the keywords to describe it. Thanks.

    PHP Code:
    $id $_SESSION['id']; // <<<<
     
    $targetPath $_SERVER['DOCUMENT_ROOT']."/members/$id/$filename"
     
    move_uploaded_file($filetmpname$targetPath); 
  2. #2
  3. Recovering Intellectual
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2006
    Location
    Orange County, CA
    Posts
    1,306
    Rep Power
    785
    can you show us your 'print_r($_SESSION);'? Need to be sure you are even getting the ID before we can continue.
    Bugs that go away by themselves come back by themselves
    Beware - your loyalty will not be rewarded
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    7
    Rep Power
    0
    Originally Posted by Matt1776
    can you show us your 'print_r($_SESSION);'? Need to be sure you are even getting the ID before we can continue.
    Thank you for your reply. Yes it has a stored value in it I'm pretty sure.

    PHP Code:
    // get user id 
    $id $_COOKIE['id']; 
    $_SESSION['id'] = $id
    Grabbed it from a cookie in another page and have echoed it as well as the session. Although I have no clue on how to show it.
  6. #4
  7. Recovering Intellectual
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2006
    Location
    Orange County, CA
    Posts
    1,306
    Rep Power
    785
    To know anything we would need:

    1. Any errors you're getting
    2. A printout of the variables, the filepathname, id, the session array

    print, or echo is pretty useful for printing values to the screen. so is print_r for printing arrays like i mentioned. If its not showing up on the screen try the http logs, commonly found somewhere like /var/log/httpd/domain-name.log or .error or something similar.

    These are the basic debugging techniques you will have to prove out to yourself before continuing - would need the results of that before knowing what is wrong.
    Bugs that go away by themselves come back by themselves
    Beware - your loyalty will not be rewarded
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    7
    Rep Power
    0
    Originally Posted by Matt1776
    To know anything we would need:

    1. Any errors you're getting
    2. A printout of the variables, the filepathname, id, the session array

    print, or echo is pretty useful for printing values to the screen. so is print_r for printing arrays like i mentioned. If its not showing up on the screen try the http logs, commonly found somewhere like /var/log/httpd/domain-name.log or .error or something similar.

    These are the basic debugging techniques you will have to prove out to yourself before continuing - would need the results of that before knowing what is wrong.
    I have never used print_r before but there are no errors at all the file just moves to the "members" folder and ignores the id variable.

    Here is the full code for that page. I am using uploadify which I'm really familiar with.
    PHP Code:
    session_start(); 
    $id $_SESSION['id']; 
    $verifyToken md5('unique_salt' $_POST['timestamp']); if (!empty($_FILES) && $_POST['token'] == $verifyToken) { 
    $filename $_FILES['Filedata']['name']; 
    $filetmpname $_FILES['Filedata']['tmp_name']; 
    $fileType $_FILES["Filedata"]["type"]; 
    $fileSizeMB = ($_FILES["Filedata"]["size"] / 102400 100000); 
    $targetPath $_SERVER['DOCUMENT_ROOT']."/members/$id/$filename"
    // Validate the file type 
    $fileTypes = array('jpg''png''gif'); // File extensions 
    move_uploaded_file($filetmpname$targetPath); } 
  10. #6
  11. Recovering Intellectual
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2006
    Location
    Orange County, CA
    Posts
    1,306
    Rep Power
    785
    Then its absolutely clear to me that your ID is not coming out of the session array and therefore i suspect as ive been suspecting this entire time that the assignment is not happening - but, you absolutely refuse to print out the content of your cookie and session arrays and i have given you exactly what you need to do it.

    php Code:
    print_r($_SESSION);
    print_r($_COOKIE);


    what is difficult about that? its "print_r". Yes, print_r
    Bugs that go away by themselves come back by themselves
    Beware - your loyalty will not be rewarded
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    7
    Rep Power
    0
    Alright will do it now sorry about that.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    7
    Rep Power
    0
    Okay it's showing this.

    453453453453453453

    453453453 is what's in the cookie.
  16. #9
  17. Recovering Intellectual
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2006
    Location
    Orange County, CA
    Posts
    1,306
    Rep Power
    785
    Exactly *what* is showing that? When I do a print_r of my session I get something that looks like, just as an example:

    Code:
    Array ( [iCompaniesPage] => 0 [sCompaniesFilter] => 1 )
    Bugs that go away by themselves come back by themselves
    Beware - your loyalty will not be rewarded
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    7
    Rep Power
    0
    Originally Posted by Matt1776
    Exactly *what* is showing that? When I do a print_r of my session I get something that looks like, just as an example:

    Code:
    Array ( [iCompaniesPage] => 0 [sCompaniesFilter] => 1 )
    Where would I find that output? and I'm using xampp btw if that's important.
  20. #11
  21. Recovering Intellectual
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2006
    Location
    Orange County, CA
    Posts
    1,306
    Rep Power
    785
    You know what? I have absolutely no idea, I would imagine its going to print onto the page you have built with PHP and presumably HTML. If this is a command line program which again I presume its not then it would print to the command line or to a logfile, such as the system log, stderr, or probably, the httpd logs.

    I have never used that development environment for php - but I imagine its not hard to find the output of a 'print' if you look for it.

    If the upload code is on another page that is being included or posted to then try printing the session out on the previous page or at the top of the included page with a "die()" thrown in afterward.
    Bugs that go away by themselves come back by themselves
    Beware - your loyalty will not be rewarded
  22. #12
  23. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    There is no difference between hard-coding the value and reading it out of the session. The only way that code could not be working is if $_SESSION['id'] doesn't contain the right value.

    If you have print_r($_SESSION) in your code and you're not seeing any output, it probably means that $_SESSION is null. If you use var_dump instead of print_r, you can confirm this.

    I'm also not sure why you keep referencing a cookie if you're using a session?
    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
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    7
    Rep Power
    0
    Originally Posted by E-Oreo
    There is no difference between hard-coding the value and reading it out of the session. The only way that code could not be working is if $_SESSION['id'] doesn't contain the right value.

    If you have print_r($_SESSION) in your code and you're not seeing any output, it probably means that $_SESSION is null. If you use var_dump instead of print_r, you can confirm this.

    I'm also not sure why you keep referencing a cookie if you're using a session?
    Lol yea that's true it was just what it felt to me but yea you're right. I just realized that when uploadify javascripted calls the upload php I don't think it triggers getting the session variable. I apologize if that was what you were trying to tell me Matt but yea. Now to figure out how would I get this data when calling php externally? I'm not too familiar with print_r are or where to find the output. I'm saying the session variable came from the cookie.
  26. #14
  27. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    The session variable is populated by calling session_start(), make sure you're doing that on your upload handling script.

    Most browsers have development tools built in that you can use to inspect the network requests that are sent while you are on a page. You can use those to view the output from the requests. The network request that your JavaScript sends to upload the file will be visible in those tools, and the output from print_r / var_dump will be visible there. print_r doesn't generate any special output, it just sends the output normally.

    Note though that print_r won't generate any output if the variable is null. I can't remember, but $_SESSION might be null before session_start() is called.

    The session variable shouldn't be coming from the cookie. Saying that doesn't really make sense unless you first put the value into a cookie and then put it into a session, but that workflow itself makes no sense. You shouldn't be reading the user ID out of a cookie at all basically.
    Last edited by E-Oreo; April 23rd, 2013 at 11:08 PM.
    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

IMN logo majestic logo threadwatch logo seochat tools logo