Uploading an image using PHP

Discussion in 'PHP' started by mokimofiki, Jul 29, 2009.

  1. #1
    Can someone look at the following code and let me know why it doesn't upload the image:

    (there is no error when doing this but just doesn't work?

    echo "<center><table cellspacing=\"3\" cellpadding=\"3\" border=\"0\">\n";
        echo "<form method=\"post\" action=\"addhome.php\" enctype = \"multipart/form-data\">\n";
        echo "<tr><td>Rendering Image:</td><td><input type=\"file\" name=\"rendering\" /></td><td></td></tr>\n";
        echo "<tr><td colspan=\"3\" align=\"right\"><input type=\"submit\" name=\"submithome\" value=\"Add Item\"></td></tr>\n";
        echo "</form></table></center>\n";
    
    
    if(isset($_POST['submithome']))
    {
    //UPLOAD PICTURE
    $filename = strtolower($_POST['rendering']);
    move_uploaded_file($_POST['rendering'], $_SERVER['DOCUMENT_ROOT']."/homes/".$filename);
    //END UPLOAD PICTURE
    }
    Code (markup):
     
    mokimofiki, Jul 29, 2009 IP
  2. Martinoes

    Martinoes Peon

    Messages:
    110
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try:

    
    echo "<center><table cellspacing=\"3\" cellpadding=\"3\" border=\"0\">\n";
        echo "<form method=\"post\" action=\"addhome.php\" enctype = \"multipart/form-data\">\n";
        echo "<tr><td>Rendering Image:</td><td><input type=\"file\" name=\"rendering\" /></td><td></td></tr>\n";
        echo "<tr><td colspan=\"3\" align=\"right\"><input type=\"submit\" name=\"submithome\" value=\"Add Item\"></td></tr>\n";
        echo "</form></table></center>\n";
    
    
     if(!empty($_FILES["rendering"])) 
    {
    //UPLOAD PICTURE
    $filename = strtolower($_POST['rendering']['name']);
    move_uploaded_file($_POST['rendering']['tmp_name'], $_SERVER['DOCUMENT_ROOT']."/homes/".$filename);
    //END UPLOAD PICTURE
    }
    PHP:
     
    Martinoes, Jul 29, 2009 IP
  3. K1llswitch

    K1llswitch Member

    Messages:
    84
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #3
    echo "<center><table cellspacing=\"3\" cellpadding=\"3\" border=\"0\">\n";
        echo "<form method=\"post\" action=\"addhome.php\" enctype = \"multipart/form-data\">\n";
        echo "<tr><td>Rendering Image:</td><td><input type=\"file\" name=\"rendering\" /></td><td></td></tr>\n";
        echo "<tr><td colspan=\"3\" align=\"right\"><input type=\"submit\" name=\"submithome\" value=\"Add Item\"></td></tr>\n";
        echo "</form></table></center>\n";
    
    
    if(isset($_POST['submithome']))
    {
    //UPLOAD PICTURE
    $filename = strtolower($_FILES['rendering']['name']);
    move_uploaded_file($_FILES['rendering']['tmp_name'], $_SERVER['DOCUMENT_ROOT']."/homes/".$filename);
    //END UPLOAD PICTURE
    }
    Code (markup):
    There you go.
     
    K1llswitch, Jul 29, 2009 IP
    mokimofiki likes this.
  4. mokimofiki

    mokimofiki Well-Known Member

    Messages:
    444
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #4
    Perfect thank you :)
     
    mokimofiki, Jul 30, 2009 IP
  5. K1llswitch

    K1llswitch Member

    Messages:
    84
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #5
    No problem.
     
    K1llswitch, Aug 3, 2009 IP
  6. johnambaram

    johnambaram Member

    Messages:
    206
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #6
    i tried this but i did not found any problem..
     
    johnambaram, Aug 3, 2009 IP