I want to use absolute paths to have it be more secure. I could use file:///, but some things don't like that beginning, so I use http://localhost/. Also, I plan on moving my site to another host, and plan to use absolute paths when I do so.
My PHP.ini says:
allow_url_fopen = On
Here's some code: Sorry it's not organized visually right now...
<?php
include 'functions.php';
include 'config.php';
include 'connect.php';
include 'sessions.php';
$abs_path = 'http://localhost/spcatv/';
$path_to_images = $abs_path.'images/';
$path_to_templates = $path_to_images.'templates/';
$image_type = array (
1 => 'navi',
2 => 'large',
3 => 'small',
);
If (!$_SESSION['image_fields'])
{
$result=get_image_fields();
If (!$result)
{
$error = 'There is an error in the image fields array';
reg_error($error);
}
}
If ($_SESSION['submitted'])
{
For ($z = 1; $z <= sizeof($image_type); $z++)
{
$type = $choice_type[$_SESSION['x']].'_'.$image_type[$z];
Switch ($type) //Selects the type, I know it's redundant, but I want it to adapt to anything...
{
//--------------[NAVIGATION]------------------------------------
case "navi":
$imagesource = $abs_path.$path_to_templates."navi.png";
$startwidth = (30);
$fontsize=11;
$path_to_store = $path_to_images.$choice_type[$_SESSION['x']].'/generated/';
break;
case "crew_navi":
$imagesource = $abs_path.$path_to_templates."navi.png";
$startwidth = (50);
$fontsize=10;
$path_to_store = $path_to_images.'navi/generated/';
break;
case "evnt_navi":
$imagesource = $abs_path.$path_to_templates."navi.png";
$startwidth = (50);
$fontsize=10;
$path_to_store = $path_to_images.'navi/generated/';
break;
case "news_navi":
$imagesource = $abs_path.$path_to_templates."navi.png";
$startwidth = (50);
$fontsize=10;
$path_to_store = $path_to_images.'navi/generated/';
break;
//--------------[DEFAULT]---------------------------------------
default:
$error = "You have gotten to this page worngly! Please follow the correct urls!";;
disaster_error($error);
break;
}
$filetype = substr($imagesource,strlen($imagesource)-4,4);
$filetype = strtolower($filetype);
Switch ($filetype)
{
case '.gif':
$image = @imagecreatefromgif($imagesource);
break;
case '.jpg':
$image = @imagecreatefromjpeg($imagesource);
break;
case '.png':
$image = @imagecreatefrompng($imagesource);
break;
}
if (!$image) die('errpr');
$font = '../images/fonts/tahoma.ttf';
$imagewidth = imagesx($image);
$imageheight = imagesy($image);
$fontwidth = imagefontwidth($font);
$fontheight = imagefontheight($font);
$string=$_SESSION['name']; //Add Abbrevation!!!!
$startheight = (($imageheight + $fontheight)/2);
$white = imagecolorallocate($image, 255, 255, 255);
$black = ImageColorAllocate($image, 0, 0, 0);
imagettftext($image, $fontsize, 0, $startwidth, $startheight, $white, $font, $string);
imagepng($image, $path_to_store.$_SESSION['id'].'_'.$image_type[$z].".png");
imagedestroy($image);
print ($path_to_store);
If ($_SESSION['method'] == 'create')
{
$query = 'Insert into '.$image_table_name.' Values (\'\',\''.$_SESSION['id'].'\',\''.$image_type[$z].'\')';
mysql_close();
}
}
}
If (!$error)
{
$_SESSION['image_done'] = 'set';
$to = 'process.php?sid='.session_id();
redirect($to);
}
Else
{
Print ('Error'.$error_codes[$error]);
die();
}
?>