Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2009
    Location
    UK
    Posts
    42
    Tokens
    0

    Default PHP Image uploading.

    PHP Code:
    <?php
    session_start
    ();
    // Admin Section
    if($_SESSION['status'] != 2){die('You must be an administrator to access this section; please <a href="login.php">login</a>');}
    require (
    "connect.php");
    require(
    "functions.php");
    include(
    "template/header.php");
    $errorMsg "";
    if(!empty(
    $_POST['submit']))
    {
     
    $title mysql_real_escape_string($_POST['title']);
     
    $link mysql_real_escape_string($_POST['link']);
     
    $cat mysql_real_escape_string($_POST['cats']);
     if(empty(
    $title)|| empty($link) || empty($cat)){$errorMsg " --- <b><u>All required(*) fields must be filled in!</u></b>";}
     else
     {
      
    $rand rand(0,999999);
      
    $image = empty($_FILES["file"]["name"]) ? "none.jpeg" "$rand$_FILES["file"]["name"];
      if(
    $image != "none.jpeg"){move_uploaded_file($_FILES["file"]["tmp_name"], $image);}
      
    mysql_query("INSERT into layouts VALUES(NULL, '$title', '$link', '$image', '0', '$cat')") or die(mysql_error());
      echo 
    "The layout has been created! - $image";
      die();
      }
     }
    echo 
    "<a href=\"admin.php\">Return to admin section!</a></br><br/><br/>
          Here you can add layouts. If you wish to add a category, please go to <a href='admin-cats.php'>this</a> section!<br/><br/>
          Create a new layout:<span style='color:#f00;'>
    $errorMsg</span>
          <form action='#' method='post' enctype='multipart/form-data'>
           <table>
            <tr><td align='right'>Title: </td><td><input type='text' name='title' value='"
    .$_POST["title"]."'> <span style='color:#f00;font-weight:bold;'>*</span></td></tr>
            <tr><td align='right'>Link to the layout: </td><td><input type='text' name='link' value='"
    .$_POST["link"]."'> <span style='color:#f00;font-weight:bold;'>*</span></td></tr>
            <tr><td>Display image (100px x 100px): </td><td><input id='file' type='file' name='file'/></td></tr>
            <tr><td colspan='2'>"
    ;listcats();echo "</td></tr>
            <tr><td colspan='2' align='center'><br /><input type='submit' name='submit' value='Create layout!'></td></tr>
           </table>
          </form>"
    ;
    include(
    "template/footer.php");
    ?>
    The code above uploads a file and puts the filename into the database into a field called image. I would like it so I can upload another image and that filename goes into another field called thumbnail.

    How would I do that?

  2. #2
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    You use the file already uploaded, size it down to create the "thumbnail", you can then move it and put it into another location then query the DB.
    Hi, names James. I am a web developer.

Posting Permissions

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