Image Hosting software?

Soldato
Joined
2 Jun 2004
Posts
18,423
I'm after a quick and easy way to add images to my blog. What I want is basically software which does exactly what "imagshack" does. Only I want to host it myself, since these image hosting websites tend to be unreliable.

Any idea's?
 
Last edited:
Soldato
OP
Joined
2 Jun 2004
Posts
18,423
That seems like overkill for what I want. I only want to host my own images, not anyone elses. Is there nothing a little simpler? :confused:

I literally just want something that lets me browse for an image on my computer, hit 'upload' and then give me the code (and thumbnail code) for posting on sites/forums.
 
Last edited:
Associate
Joined
30 Nov 2003
Posts
1,570
If you only want to host your own images and nobody elses then surely you need a password protected uploader like I suggested. Just disable registration so nobody else can use it but you.

There probably is something simpler out there but the one I suggested it pretty basic to be honest.
 
Associate
Joined
25 Aug 2006
Posts
1,089
Why dont you get free hosting?

You then just need to point it to the folder on your server.

Domain names can be bought for something like ~£3

that way no one has access to your pictures

Chris
 
Soldato
Joined
6 Feb 2004
Posts
20,647
Location
England
i recently made a simple file uploader in php. orignally it required mysql but as you only want it for one user, i've removed the need for it. so now it's all self contained in one file. the only config change you'll have to make is to the $here variable - point this at the parent folder of where the script will be sitting.

features-
creates thumbnails
generates bbcode for forums
supports jpg/gif/png files
size limit 2mb
option to delete file

limitations-
all image details are displayed on one page :p

preview-
2001508331161511357_rs.jpg


and here's the source...

Code:
<?php
session_start();
$here = 'http://marc2003.dyndns.org/ocuk/';
$files = 'files/';
$thumbs = 'thumbs/';
@mkdir($files);
@mkdir($thumbs);
function im($type, $b, $thumb) {
	switch($type) {
		case 'image/png':
		case 'image/x-png':
			imagepng($b, $thumb);
			break;
		case 'image/gif':
			imagegif($b, $thumb);
			break;
		case 'image/jpeg':
		case 'image/pjpeg':
			imagejpeg($b, $thumb);
			break;
	}
	imagedestroy($b);
}
if($_POST['upload']) {
	$name = $_FILES['userfile']['name'];
	$tmp_name  = $_FILES['userfile']['tmp_name'];
	$size = $_FILES['userfile']['size'];
	$type = $_FILES['userfile']['type'];
	$error = $_FILES['userfile']['error'];
	switch($error) {
		case 0:
			switch($type) {
				case 'image/png':
				case 'image/x-png':
					$im = imagecreatefrompng($tmp_name);
					break;
				case 'image/gif':
					$im = imagecreatefromgif($tmp_name);
					break;
				case 'image/jpeg':
				case 'image/pjpeg':
					$im = imagecreatefromjpeg($tmp_name);
					break;
				default:
					$_SESSION['message'] = 'sorry, that wasn\'t a valid file type. only jpg/png/gif files are allowed!';
			}
			while(file_exists($files.$rand.$name)) {
				$rand = rand(1, 9999);
			}
			$name = $rand.$name;
			if($im && move_uploaded_file($tmp_name, $files.$name)) {
				$width = imagesx($im);
				$height = imagesy($im);
				$thumb = $thumbs.$name;
				if(($width <= 200) && ($height <= 200)) {
					im($type, $im, $thumb);
				} else {
					$ratio = $width/$height;
					if ($ratio>1){
						$newwidth = 200;
						$newheight = 200/$ratio;
					} else {
						$newwidth = 200*$ratio;
						$newheight = 200;
					}
					$new = imagecreatetruecolor($newwidth,$newheight + 15);
					imagecopyresampled($new, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
					$white = imagecolorallocate($im, 255, 255, 255);
					$text = $width.'x'.$height.' '.intval($size/1024).'KB';
					imagestring($new, 2, 5, $newheight, $text, $white);
					im($type, $new, $thumb);
				}
			} else {
				$_SESSION['message'] = 'unable to process uploaded file!';
			}
			break;
		case 1:
		case 2:
			$_SESSION['message'] = 'your file must be under 2mb!';
			break;
		case 3:
			$_SESSION['message'] = 'unable to process uploaded file!';
			break;
		case 4:
			$_SESSION['message'] = 'you didn\'t select a file!';
	}
	header("Location: $here");
	exit;
}
if($_POST['delete']) {
	$name = $_POST['name'];
	unlink($files.$name);
	unlink($thumbs.$name);
	header("Location: $here");
	exit;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
body {background-color: #E6E6FA; font-family: verdana, sans-serif; }
.main {margin-bottom: 5px; width: 750px; height: 25px; }
.thumbnail {float: left; width: 220px; height: 375px; margin-right: 28px; margin-bottom: 5px; padding: 5px; }
.main, .thumbnail {background-color: #F0F8FF; border-style: dotted solid; border-width: 1px; border-color: #999999; }
p { margin-top: 4px;  margin-bottom: 4px; margin-left: 4px; margin-right: 4px; }
img { border: 0; }
</style>
</head>
<body>
<div class="main">
<form action="" method="post" enctype="multipart/form-data" name="uploadform">
<p style="margin-top: 1px; margin-bottom: 1px;">
<input name="MAX_FILE_SIZE" type="hidden" value="2000000">
<input name="userfile" type="file" size="40">
<input type="submit" name="upload" value="upload"></p>
</form>
</div>
<div style="width: 800px">
<?php 
if($_SESSION['message']) {
	echo '<div class="main"><p style="color: #FF0000;"><label>&nbsp;</label>'.$_SESSION['message']."</p></div>\n";
	unset($_SESSION['message']);
}
$dh = opendir($files);
while (($name = readdir($dh)) !== false) {
    	if($name != "." && $name != "..") {
		?>
        	<div style="text-align: center;" class="thumbnail">
		direct link to full image -
		<p><textarea style="width: 200px" rows="1" cols="2" readonly="readonly"><?php echo $here.$files.$name; ?></textarea></p>
		thumbnail for forums -
		<p><textarea style="width: 200px" rows="1" cols="2" readonly="readonly">[url=<?php echo $here.$files.$name; ?>][img]<?php echo $here.$thumbs.$name; ?>[/img][/url]</textarea></p>
		<p style="height: 215px"><a href="<?php echo $here.$files.$name; ?>"><img src="<?php echo $here.$thumbs.$name; ?>" alt="<?php echo $name; ?>"></a></p>
		<form action="" method="post" name="form">
		<p><input type="hidden" name="name" value="<?php echo $name; ?>">
		<input type="submit" name="delete" value="delete"></p>
		</form>
		</div>
		<?php
    	}
}
closedir($dh);
?>
</div>
</body>
</html>
 
Last edited:
Back
Top Bottom