Trouble With Upload File

Discussion in 'PHP' started by scottlpool2003, Oct 15, 2012.

  1. #1
    Can't work out for the life of me why it isn't working... Everything outputs okay but it won't move the uploaded file...

    Upload form:
    <form enctype="multipart/form-data" method="post" action="addimg.php">
    <input type="file" name="fileToUpload" /><br />
    </div>
    <input type="submit" value="Upload File" style="width:100%;border:2px solid silver;background:beige;padding:10px;"/>
    </form>
    HTML:
    PHP Code ($dir outputs correctly but is needed as multiple versions of the same website are stored in subfolders from the root folder)
    
    
    //$time = time();
    //$fileToUpload = $time . $fileToUpload;
    $dir = "/uploads/";
    
    echo "<table border=\"1\">";
    echo "<tr><td>Client Filename: </td>
       <td>$time" . $_FILES["fileToUpload"]["name"] . "</td></tr>";
    echo "<tr><td>File Type: </td>
       <td>" . $_FILES["fileToUpload"]["type"] . "</td></tr>";
    echo "<tr><td>File Size: </td>
       <td>" . ($_FILES["fileToUpload"]["size"] / 1024) . " Kb</td></tr>";
    echo "<tr><td>Name of Temp File: </td>
       <td>" . $_FILES["fileToUpload"]["tmp_name"] . "</td></tr>";
    echo "</table>";
    
    move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], "/$dir/images/" . $_FILES["fileToUpload"]["name"]);
    
    PHP:
    Is there anything obviously wrong with the code? I've tried taking out the $time function and it still doesn't output correctly. Folder is CHMOD correctly and as I say it all outputs in the table so it's down to the move_uploaded_file function.
     
    scottlpool2003, Oct 15, 2012 IP
  2. plussy

    plussy Peon

    Messages:
    152
    Likes Received:
    5
    Best Answers:
    9
    Trophy Points:
    0
    #2
    Is there anything in $_FILES['fileToUpload']['error']?
     
    plussy, Oct 15, 2012 IP
  3. rainborick

    rainborick Well-Known Member

    Messages:
    424
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    120
    #3
    The path to the images/ directory may be incorrect. Remember, it's not a URL, it's a pathname so when you start with "/$dir", it assumes the path begins with the server root. Try removing the leading "/" or make the entire path name relative to where the script resides on your server.
     
    rainborick, Oct 15, 2012 IP
  4. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #4
    Thanks for the help, now fixed:

     
    scottlpool2003, Oct 16, 2012 IP
  5. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #5
    scottlpool2003, Oct 16, 2012 IP
  6. plussy

    plussy Peon

    Messages:
    152
    Likes Received:
    5
    Best Answers:
    9
    Trophy Points:
    0
    #6
    don't see the links as I block adverts :p didn't realise they just copied part of a previous post lol :p
     
    plussy, Oct 16, 2012 IP
  7. sekhar203

    sekhar203 Active Member

    Messages:
    96
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #7
    good information...thanks to all
     
    sekhar203, Oct 16, 2012 IP
  8. MrPJH

    MrPJH Well-Known Member

    Messages:
    1,066
    Likes Received:
    7
    Best Answers:
    1
    Trophy Points:
    155
    #8
    in vbulletin forums when you talk about a PHP function it automatically Links to PHP.NET
    move_uploadeed_fil is a PHP.net fiunction which will link to its page on most of the wyshwing editors
     
    MrPJH, Oct 18, 2012 IP
  9. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #9
    The user we were talking about has had their reply removed and they appear to have been banned so I think you've missed what we were talking about regarding bots.
     
    scottlpool2003, Oct 18, 2012 IP