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!


Page 1 of 4 1234 LastLast
Results 1 to 10 of 38
  1. #1
    Join Date
    May 2006
    Location
    Hull
    Posts
    7,701
    Tokens
    2,430
    Habbo
    Moh

    Latest Awards:

    Default [PHP] Image Upload

    Because finding a working, customizable image upload script is hard nowadays, I decided to make my own (Not the best upload script, but it works).
    This is fully customizable, and you can easily make it so that it submits the images to a database allowing you to add "Recently uploaded" and a "Share Image" pages. If you need help with that bit, just reply and ill tell you what to add

    All you have to do is removed "exit;" from line 11 just to show that you actually read this and change the domains to your domain (Remember to CHMOD your folder).
    Credit to Invent for telling me how to use arrays.

    Demo: www.v-habbo.com/upload
    Download link:
    http://v-habbo.com/upload/imager.zip


    upload.php

    PHP Code:
     <?php
    $dir 
    "/home/vhabbo/public_html/images/uploads"// This is the directory you wish your images to be uploaded. Change "vhabbo" to your username and remember to CHMOD to 777.
    $maxsize "10000000"// This is the max file size
    $types_alowed = array("gif""png""bmp""jpg""jpeg"); // These are the files alowed to upload
    $websiteurl = ("v-habbo.com"); // Change this to your website URL, adding a www. is additional.

    // Only edit below if you have knowledge in php.
    if(isset($_FILES["file"])) {
        
    $file $_FILES["file"]["name"];
        
    $dot explode"."$file);
        
    $tempname $_FILES["file"]["tmp_name"];    
        
        
    $tmpname $_FILES["file"]["tmp_name"];
    $info getimagesize$tmpname );
    $re1 '(image)';

    if ( 
    $_FILES["file"]["size"] > $maxsize || $file == "" ) {
    echo ( 
    "<p>The following errors occured:<ul>" );
        
    $end "</ul></p>";

    if(
    $file == "") {
        echo(
    "<li>Please complete the required field \"File\".</li>");
        
    $error2 "1";
    }
    if(
    $_FILES["file"]["size"] > $maxsize) {
        echo(
    "<li>The size of your image is too big.</li>");
    }
    }
    else {
    if ( 
    preg_match"/" $re1 "/is"image_type_to_mime_type$info[2] ) ) ) {

        
    $name uniqid("img").$_FILES["file"]["name"]; // This will create a random name for the file
        
    $newname str_replace" ""_"$name); // This will replace any spaces in the file name
        
    move_uploaded_file($tempname"$dir/$newname");
        echo(
    "<img src=\"http://$websiteurl/images/uploads/$newname\" border=\"0\" />
        <fieldset>
        <legend>Direct Link:</legend>
        <input type=\"text\" name=\"direct\" value=\"http://
    $websiteurl/images/uploads/$newname\" class=\"file\" size=\"100%\"><br>
        </fieldset>
        <legend>HTML Clode:</legend>
        <input type=\"text\" name=\"direct\" value=\"&lt;a href=&quot;http://www.
    $websiteurl/upload&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://$websiteurl/images/uploads/$newname&quot; border=&quot;0&quot;&gt;&lt;/a&gt;\" class=\"file\" size=\"100%\"><br>
        </fieldset>"
    );
    }
    else {
        echo ( 
    "<p>The following errors occured:<ul>" );
        
    $end "</ul></p>";
        echo(
    "<li>You can only upload image files.</li></ul></p>");
        echo(
    "$end");
    }

    }
    }
    else {
    ?>
    <form method="post" enctype="multipart/form-data">
    <fieldset>
    <legend>Select File:</legend>
    <input type="file" name="file" class="file" size="20"><br>
    </fieldset>
    <br>
    <input class="submit" type="submit" value="Upload" name="submit">
    </form>
    <?
    }
    ?>
    Post updated by ,Jess, (Forum Super Moderator): On request of user.
    Last edited by ,Jess,; 20-06-2008 at 04:56 PM.

  2. #2
    Join Date
    Sep 2006
    Location
    Evanston, Illinois.
    Posts
    2,361
    Tokens
    0

    Latest Awards:

    Default

    Nice, this should be put in tutorials except it isn't one. It'll prevent a lot of threads.

    Quite nice, although they're is some picky things, such as when you concatinate strings, you should use ' ' instead of " ", without the space, as ' ' is faster than " ".
    uniqid, can be a bit slow, although it isn't deprecated yet.

    Other than that it's really good! WD
    How could this hapen to meeeeeeeeeeeeeee?lol.

  3. #3
    Join Date
    Apr 2008
    Location
    England.
    Posts
    1,324
    Tokens
    0

    Latest Awards:

    Default

    Very nice but it would be better if you displayed a link as to where their image is.

  4. #4
    Join Date
    Nov 2007
    Posts
    1,253
    Tokens
    150

    Latest Awards:

    Default

    Point it though, that this is just a base. If people want to add the links to the users image then they can do it by themselves.

    Nicely done btw.


    www.fragme.co = a project.

  5. #5
    Join Date
    Apr 2008
    Location
    England.
    Posts
    1,324
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by GasFMatt View Post
    Point it though, that this is just a base. If people want to add the links to the users image then they can do it by themselves.

    Nicely done btw.
    Take someone who knows jack crap about php, how do you expect him to add in code?

  6. #6
    Join Date
    Dec 2005
    Posts
    6,228
    Tokens
    1,145

    Latest Awards:

    Default

    Looks quite nice, i'll try it out now.

    EDIT;
    Parse error: syntax error, unexpected '/', expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/biolabs/public_html/test.php on line 42
    Last edited by jackass; 20-06-2008 at 03:07 PM.
    i'm out of touch, i'm out of love
    i'll pick you up when you're getting down
    and out of all these things i've done
    i think i love you better now

  7. #7
    Join Date
    May 2006
    Location
    Hull
    Posts
    7,701
    Tokens
    2,430
    Habbo
    Moh

    Latest Awards:

    Default

    Quote Originally Posted by Biohazard View Post
    Looks quite nice, i'll try it out now.

    EDIT;
    Urg, I wish the forum didn't change the code.

    Try this, I had to remove the BB Code part
    PHP Code:
     <?php
    $dir 
    "/home/vhabbo/public_html/images/uploads"// This is the directory you wish your images to be uploaded. Change "vhabbo" to your username and remember to CHMOD to 777.
    $maxsize "10000000"// This is the max file size
    $types_alowed = array("gif""png""bmp""jpg""jpeg"); // These are the files alowed to upload
    $websiteurl = ("v-habbo.com"); // Change this to your website URL, adding a www. is additional.

    // Only edit below if you have knowledge in php.
    if(isset($_FILES["file"])) {
        
    $file $_FILES["file"]["name"];
        
    $dot explode"."$file);
        
    $tempname $_FILES["file"]["tmp_name"];    
        
        
    $tmpname $_FILES["file"]["tmp_name"];
    $info getimagesize$tmpname );
    $re1 '(image)';

    if ( 
    $_FILES["file"]["size"] > $maxsize || $file == "" ) {
    echo ( 
    "<p>The following errors occured:<ul>" );
        
    $end "</ul></p>";

    if(
    $file == "") {
        echo(
    "<li>Please complete the required field \"File\".</li>");
        
    $error2 "1";
    }
    if(
    $_FILES["file"]["size"] > $maxsize) {
        echo(
    "<li>The size of your image is too big.</li>");
    }
    }
    else {
    if ( 
    preg_match"/" $re1 "/is"image_type_to_mime_type$info[2] ) ) ) {

        
    $name uniqid("img").$_FILES["file"]["name"]; // This will create a random name for the file
        
    $newname str_replace" ""_"$name); // This will replace any spaces in the file name
        
    move_uploaded_file($tempname"$dir/$newname");
        echo(
    "<img src=\"http://$websiteurl/images/uploads/$newname\" border=\"0\" />
        <fieldset>
        <legend>Direct Link:</legend>
        <input type=\"text\" name=\"direct\" value=\"http://
    $websiteurl/images/uploads/$newname\" class=\"file\" size=\"100%\"><br>
        </fieldset>
        <legend>HTML Clode:</legend>
        <input type=\"text\" name=\"direct\" value=\"&lt;a href=&quot;http://www.
    $websiteurl/upload&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://$websiteurl/images/uploads/$newname&quot; border=&quot;0&quot;&gt;&lt;/a&gt;\" class=\"file\" size=\"100%\"><br>
        </fieldset>"
    );
    }
    else {
        echo ( 
    "<p>The following errors occured:<ul>" );
        
    $end "</ul></p>";
        echo(
    "<li>You can only upload image files.</li></ul></p>");
        echo(
    "$end");
    }

    }
    }
    else {
    ?>
    <form method="post" enctype="multipart/form-data">
    <fieldset>
    <legend>Select File:</legend>
    <input type="file" name="file" class="file" size="20"><br>
    </fieldset>
    <br>
    <input class="submit" type="submit" value="Upload" name="submit">
    </form>
    <?
    }
    ?>
    If you want the BB Code part, just simply download the file
    http://v-habbo.com/upload/imager.zip
    Last edited by ,Jess,; 20-06-2008 at 04:57 PM. Reason: updating post on request

  8. #8
    Join Date
    Dec 2005
    Posts
    6,228
    Tokens
    1,145

    Latest Awards:

    Default

    Now its...

    Parse error: syntax error, unexpected '/', expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/biolabs/public_html/test2.php on line 43
    i'm out of touch, i'm out of love
    i'll pick you up when you're getting down
    and out of all these things i've done
    i think i love you better now

  9. #9
    Join Date
    May 2006
    Location
    Hull
    Posts
    7,701
    Tokens
    2,430
    Habbo
    Moh

    Latest Awards:

    Default

    Quote Originally Posted by Biohazard View Post
    Now its...
    Shouldn't be?
    I edited it a couple of mins ago, try new 1

  10. #10
    Join Date
    Dec 2005
    Posts
    6,228
    Tokens
    1,145

    Latest Awards:

    Default

    Yeah, works now - thanks.
    i'm out of touch, i'm out of love
    i'll pick you up when you're getting down
    and out of all these things i've done
    i think i love you better now

Page 1 of 4 1234 LastLast

Posting Permissions

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