TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 03-26-2008, 03:13 PM   #1 (permalink)
The Contributor
 
Join Date: Dec 2007
Posts: 31
Thanks: 0
TerrorRonin is on a distinguished road
Default Simple Image Uploader

I still see an abundance of image uploaded sites popping up.. so I got bored, and had a domain lying around, so I built a very simple application that people can use if they'd like.

A live (permanent) demo of the script is located at Free Image Hosting!

You can upload images there if you'd like, or you build your own, by using the source code shown below!
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <title>Free Image Hosting!</title>
    <style type="text/css">
        body {
            margin: 0;
            padding: 50px 0 0;
            font-family: "Lucida Sans Unicode", Verdana, Arial, Sans-Serif;
            font-size: 11px;
        }
        
        a {
            color: #000000;
        }
        
        h1 {
            margin: 0;
            padding: 0;
        }
        
        h2 {
            margin: 10px 0;
            padding: 0:
            font-size: 12px;
        }
        
        #wrapper {
            background-color: #f0f0f0;
            border: 2px solid #d9d9d9;
            border-left: none;
            border-right: none;
            margin: 10px 0;
            padding: 10px;
            line-height: 25px;
            font-size: 12px;
        }
    </style>
</head>
<body><center>

    <?php
    
    $dir 
dirname(__FILE__) . '/uploads/';
    
    if (
is_dir($dir))
    {
        if (
$dh opendir($dir))
        {
            
$filecount '0';
            
            while ((
$file readdir($dh)) !== false)
            {
                if(!(
$file == '.' || $file == '..'))
                {
                    ++
$filecount;
                }
            }
            
closedir($dh);
            
            echo 
"\n";
        }
    }
    else
    {
        echo 
"You must create a /upload/ directory before this script will work.\n";
    }
    
    
?>
    <h1>Free Image Hosting!</h1>
    <div id="wrapper">
        <form method="post" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>">
            Upload Image <input type="file" name="userfile" />
            <input type="submit" name="submit" value="Upload" />
        </form>
        <strong>Allowed Extensions:</strong> gif, jpg, bmp, png<br />
    </div>
    Currently Hosting <strong><?php echo $filecount?></strong> images!<br />
    
    <?php
    
        
if(isset($_POST['submit']))
        {
            if(
is_uploaded_file($_FILES['userfile']['tmp_name']))
            {
                if ((
$_FILES['userfile']['type']=="image/gif") || ($_FILES['userfile']['type']=="image/bmp") || ($_FILES['userfile']['type']=="image/pjpeg") || ($_FILES['userfile']['type']=="image/jpeg") || ($_FILES['userfile']['type']=="image/png") ) 
                {
                    
# // -- Upload Process Starts
                        
                    
$file '/uploads/' date('mdyhis') . '-' basename($_FILES['userfile']['name']);
                        
                    if (@
move_uploaded_file($_FILES['userfile']['tmp_name'], "./" $file))
                    {
                        
$url 'http://' $_SERVER['HTTP_HOST'] . $file;
                        
                        echo 
"<h2>File URL: <a href=\"{$url}\">{$url}</a></h2>\n";
                    }
                    else
                    {
                        echo 
"<h2>Unable to upload file to webserver, please verify that this directory exists</h2>\n";
                    }
                        
                    
# // -- Upload Process Ends
                
}
                else
                {
                    echo 
"<h2>Unacceptable File Type.  Please upload only as specified.</h2>\n";
                }
            }
        }
        else
        {
            echo 
"<h2></h2>\n";
        }
    
    
?>

</center>
</body>
</html>
If any of you have security fixes, or would like to add to this script, please do. I'll add any fixes that you like, etc.. maybe it can become a cool little script in the end :) I know it's not all that advanced right now, but this was just for fun :P
TerrorRonin is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 04:54 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design