Anda di halaman 1dari 4

<?

php
/*
Template Name: Imagehost
*/
?>
<?php get_header(); ?>
<div id="content">
<div id="body">
<h2><?php the_title();?></h2>
<?php
$address = "http://127.0.0.1/images/public/";
//** Please put the exact location of the foler where you'd like the images to b
e saved. ie "http://image.xxxxxxx.com/images/" **//
$yoursite = "http://127.0.0.1";
//** Change XXXXX.XXXXX to your site for the Image hosted by. **//
$sitename = "xxxxxxx.com";
//** This is used for the header.php section of the site, if used. (not included
) **//
//define a maxim size for the uploaded images in Kb
define ("MAX_SIZE","500");
function RemoveExtension($strName)
{
$ext = strrchr($strName, '.');
if($ext !== false)
{
$strName = substr($strName, 0, -strlen($ext));
}
return $strName;
}
$Name = $image;
//This function reads the extension of the file. It is used to determine if the
file is an image by checking the extension.
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
//This variable is used as a flag. The value is initialized with 0 (meaning no e
rror found).
//and it will be changed to 1 if an error occurs.
//If the error occurs the file will not be uploaded.
$errors=0;
//Checks if the form has been submitted.
if(isset($_POST['Submit']))
{
//Reads the name of the file the user submitted for uploading.
$image=$_FILES['image']['name'];
//If it is not empty.
if ($image)
{
//Get the original name of the file from the clients machine.
$filename = stripslashes($_FILES['image']['name']);
//Get the extension of the file in a lower case format.
$extension = getExtension($filename);
$extension = strtolower($extension);
//If it is not a known extension, we will suppose it is an error and will not up
load the file.
//Otherwise we will do more tests.
if (($extension == "gif"))
{
//Print error message.
echo '<h3 class="color-6">The extension .GIF is not wanted here. Begone with ye!
</h3>';
$errors=1;
}
elseif (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")
)
{
//Print error message.
echo '<h1 class="color-8">Unknown extension</h1>';
$errors=1;
}
else
{
//Get the size of the image in bytes.
//$_FILES['image']['tmp_name'] is the temporary filename of the file
//in which the uploaded file was stored on the server.
$size=filesize($_FILES['image']['tmp_name']);
//Compare the size with the maxim size we defined and print error if bigger.
if ($size > MAX_SIZE*1024)
{
echo '<h3 class="color-6">You have exceeded the size limit.</h3>';
$errors=1;
}
//We will give a unique name, for example the time in unix time format / MD5 ran
dom generated.
$image_name=RemoveExtension($filename).'.'.substr(md5(rand(0,9999)), 1, 10).'.'.
$extension;
//The new name will be containing the full path where will be stored (images fol
der).
$newname="images/public/".$image_name;
//We verify if the image has been uploaded, and print error instead.
$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied)
{
echo '<h3 class="color-6">Copy unsuccessfull.</h3>';
$errors=1;
}
//else
//{
//// the new thumbnail image will be placed in images/thumbs/ folder
//$thumb_name='images/thumbs/thumb_'.$image_name;
//// call the function that will create the thumbnail. The function will get as
parameters the image name, the thumbnail name and the width and height desired f
or the thumbnail
//$thumb=make_thumb($newname,$thumb_name,WIDTH,HEIGHT);
//}
}
}
}
//If no errors register, print the success message.
if(isset($_POST['Submit']) && !$errors)
{
echo '<h3 class="color-6">Image Uploaded Successfully ';?>
<a href="<?php echo $address ."". $image_name ; ?>" target="_blank"><u>View Ful
l Image</u></a>
<?php echo '</h3><br/><div style="margin: 0 auto 0 200px;"><img class="hostimage
" src="http://127.0.0.1/'.$thumb_name.'"></div>';
include_once("includes.php");
}
?>
<?php
$imglink = 'images/public/';
$imglist='';
//$img_folder is the variable that holds the path to the image thumbsnail. E.G.
= images/thumbs/
//See that you don't forget about the "/" at the end.
$img_folder = "images/thumbs/";
mt_srand((double)microtime()*1000);
//Use the directory class.
$imgs = dir($img_folder);
//Read all files from the directory, checks if are images and adds them to a lis
t (see below how to display flash banners).
while ($file = $imgs->read()) {
if eregi("jpg", $file) || eregi("png", $file) || eregi("bmp", $file) || eregi("i
co", $file))
$imglist .= "$file ";
} closedir($imgs->handle);
//Put all images into an array.
$imglist = explode(" ", $imglist);
$no = sizeof($imglist)-2;
//Generate a random number between 0 and the number of images.
$random = mt_rand(0, $no);
$image = $imglist[$random];
//echo '<a href="'.$yoursite.'/'.$img_folder.$image.'"><img src="'.$yoursite.'/'
.$img_folder.$image.'" alt="" border="0"></a>';
// echo '<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase
="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,
0,29,0" width="150" height="150">
// <param name="movie" value="'.$img_folder.$image.'">
// <param name="quality" value="high">
// <embed src="'.$img_folder.$image.'" quality="high" pluginspage="http://ww
w.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="
150" height="150"></embed></object>';
?>
<?php
//Display image.
//echo '<img src="'.$yoursite.'/'.$img_folder.$image.'" alt="" border="0">'; ?>
<h4 class="color-2">Only .jpg .bmp .ico and .png are allowed</h4>
<form name="newad" method="post" enctype="multipart/form-data" action="">
<input type="file" name="image" style="height:24px;"/><!--<p><input type="text"
name="tags" />add any tags (seperate by comma: e.g. car, 2008, Ford,)</p>-->
<input type="submit" name="Submit" value="Upload" />
</form>
</div>
<?php get_sidebar(); ?>
</div>
<div class="clear"></div>
<?php get_footer(); ?>

Anda mungkin juga menyukai