<?
// Where the file is going to be placed
$target_path = "uploads/";
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$_FILES['uploadedfile']['tmp_name'];
// If we have uploaded correctly...
$extensions = array("JPG","jpg","JPEG","jpeg"); //File Types
$check = $target_path;
$explosion = explode(".", $check);
$name = $explosion[0]; //This is the real name of the file
$extension = $explosion[1]; //This is the extension of the full file
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
if (!in_array($extension, $extensions)) {
echo "You have to upload a file ending in .jpg in order for us to generate your favicon";
unlink ($target_path); // delete the original file
} else {
echo "We have successfully generated your icon!<Br>";
// Now actually generate it
$im = imagecreatefromjpeg($target_path);
list($width, $height) = getimagesize($target_path); // get the width and height of the jpg
$image_p = imagecreatetruecolor("16", "16"); // create a 16x16 canvas to play with
imagecopyresampled($image_p, $im, 0, 0, 0, 0, "16", "16", $width, $height); // resize jpg to 16x16
$num = rand (1,99999); // generate a random number between 1 and 99999
$output = $num."-favicon.ico"; // add the number to a string with -favicon.ico
imagepng($image_p,$output); // make a .png file (icon file) from our data
imagedestroy ($im); // close gd library
echo "<img src = \"http://www.swansoninternet.com/phpincludes/$output\"><br>Right click on the image and choose save. Save the image as favicon.ico and then upload into your base directory"; // show our icon with information
unlink ($target_path); // delete the original file
}
} else{
echo "Upload a .jpg file to convert it to a favicon!";
}
?>
<title>Favicon Generator</title>
<style type="text/css">
<!--
body,td,th {
font-family: Tahoma, Helvetica, sans-serif;
font-size: small;
color: #666666;
}
-->
</style><form enctype="multipart/form-data" action="<? $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Create Favicon" />
</form>