Jump to content

Favicon Generator


eaglelegend

Recommended Posts

Hi!,

 

I found this free favicon generator code off the net, though as it didnt actually upload to my site when I asked, I am beginning to wonder, does it actually work??

 

Since I still cannot master PHP, I am guessing that the code, being an upload type of code, it can be risky, because my experience with upload codes in the past have not been very sweet tbh - hackers and all.

 

So, would you mind if you have a quick look through the code, I dont know what that http://www.swansoninternet.com/phpincludes/$output is for, but looking at the whole line, I certainly havent seen any image I uploaded show on the page...

 

Help is much appreciated!, thanks!

 

<?php

// Where the file is going to be placed 

$target_path = "/icons/";



/* Add the original filename to our target path.  

Result is "/icons/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="<?php $_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>

 

Link to comment
https://forums.phpfreaks.com/topic/153020-favicon-generator/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.