move_uploaded_file error

Discussion in 'PHP' started by Nick, Jan 17, 2008.

  1. #1
    		
    $p=mysql_query('SELECT download_path from config');
    $path = $p[0].$_FILES['upload']['name'];
    move_uploaded_file($_FILES['upload']['tmp_name'], $path);
    
    Code (markup):
    The script is attempting to move the file to "/home/xxxxx/downloads/" which I've got CHMODed to 777... anything else that could be causing this problem?
     
    Nick, Jan 17, 2008 IP
  2. neanton

    neanton Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    you've forgotten to do mysql_fetch_assoc after query. this will look like:

    $p=mysql_query('SELECT download_path from config');
    $row = mysql_fetch_assoc($p);
    $path = $row['download_path'].$_FILES['upload']['name'];
    move_uploaded_file($_FILES['upload']['tmp_name'], $path);
     
    neanton, Jan 17, 2008 IP
  3. Nick

    Nick Peon

    Messages:
    52
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    
    $p=mysql_query('SELECT download_path from config');
    		$p_result=mysql_result($p, 0);
    
    		$path = $p_result.$_FILES['upload']['name'];
    
    Code (markup):
    I fixed it just moments before you posted using this. While this code works is it acceptable or am I going to have problems if I use it elsewhere?
     
    Nick, Jan 17, 2008 IP
  4. neanton

    neanton Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Your code is OK, but using associative arrays is better practice. Your code will be more readable ;)
     
    neanton, Jan 17, 2008 IP
  5. Nick

    Nick Peon

    Messages:
    52
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thank you very much for your help :)
     
    Nick, Jan 17, 2008 IP
  6. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #6
    echo $path before

    move_uploaded_file($_FILES['upload']['tmp_name'], $path);

    If the directory is indeed correct, check that the parent directories also are chmoded to 777.

    Also check the ownership (chown,chgrp) to be general (either apache or the username).

    Peace,
     
    Barti1987, Jan 17, 2008 IP