I will start off by saying very quickly I am completely new to PHP. I found a fairly nice PHP script to begin learning from: looking at the fuctions, returns and so forth. Without further ado, I have seemingly come very close to executing a "favicon generator script" at http://www.cornerlinks.com but Im not getting a proper return.
Here is the PHP code I am using which in my "public_html" folder is called "script.php"
<?php
function generate_favicon(){
// Create favicon.
$postvars = array("image" => trim($_FILES["image"]["name"]),
"image_tmp" => $_FILES["image"]["tmp_name"],
"image_size" => (int)$_FILES["image"]["size"],
"image_dimensions" => (int)$_POST["image_dimensions"]);
$valid_exts = array("jpg","jpeg","gif","png");
$ext = end(explode(".",strtolower(trim($_FILES["image"]["name"]))));
$directory = "favicon/"; // Directory to save favicons. Include trailing slash.
// Check not larger than 175kb.
if($postvars["image_size"] <= 179200){
// Check is valid extension.
if(in_array($ext,$valid_exts)){
if($ext == "jpg" || $ext == "jpeg"){
$image = imagecreatefromjpeg($postvars["image_tmp"]);
}
else if($ext == "gif"){
$image = imagecreatefromgif($postvars["image_tmp"]);
}
else if($ext == "png"){
$image = imagecreatefrompng($postvars["image_tmp"]);
}
list($width,$height) = getimagesize($postvars["image_tmp"]);
$newwidth = $postvars["image_dimensions"];
$newheight = $postvars["image_dimensions"];
$tmp = imagecreatetruecolor($newwidth,$newheight);
// Copy the image to one with the new width and height.
imagecopyresampled($tmp,$image,0,0,0,0,$newwidth,$newheight,$width,$height);
$rand = rand(1000,9999);
$filename = "./".$directory.$rand.$postvars["image"];
// Create image file with 100% quality.
if(is_writable($directory)){
imagejpeg($tmp,$filename,100);
// Image created, now rename it to its
$ext_pos = strpos($postvars["image"],"." . $ext);
$strip_ext = substr($postvars["image"],0,$ext_pos);
// Rename image to .ico file
rename($filename,"./favicon/".$strip_ext.".ico");
return "<strong>Icon Preview:</strong><br/>
<img src=\"./favicon/".$strip_ext.".ico\" border=\"0\" title=\"Favicon Image Preview\" style=\"padding: 4px 0px 4px 0px;background-color:#e0e0e0\" /><br/>
Favicon successfully generated. <a href=\"./favicon/".$strip_ext.".ico\" target=\"_blank\" name=\"Download favicon.ico now!\">Click here to download your favicon.</a>";
} else {
return "The directory: \"".$directory."\" is not writable.";
}
imagedestroy($image);
imagedestroy($tmp);
} else {
return "File size too large. Max allowed file size is 175kb.";
}
} else {
return "Invalid file type. You must upload an image file. (jpg, jpeg, gif, png).";
}
}
if(isset($_GET["do"])){
if($_GET["do"] == "create"){
if(isset($_POST["submit"])){
$generate_favicon = "<p>".generate_favicon()."</p>";
} else {
$generate_favicon = "";
}
}
}
?>
Next, is the the HTML portion which is as follows:
<form action="index.php?do=create" method="post" enctype="multipart/form-data">
Image Dimensions: <select name="image_dimensions" style="width: 170px">
<option value="16">16px x 16px</option>
<option value="32">32px x 32px</option>
</select><br/><br/>
<span style="font-size: 14pt">Favicon Image:</span><br/>
<input type="file" name="image" size="40" /><br/><br/>
<input type="submit" name="submit" value="Submit!" style="font: 14pt verdana" />
</form>
So in my "public_html" there is the following files: index.html (just above), script.php (which is the code above html), style.css, "favicon" folder, "image" folder. That's it. I have seemingly executed everything but the return accordingly. Please help with any suggestions. Thank you so much and Merry Christmas