Lionel
01-17-2007, 03:22 AM
This will allow you to upload an image with your link
Sorry guys, instructions are a little messy, I am in a hurry. I have this installed for a while now and I just wanted to share.
Alter table_prefix adv_links (use phpadmin to add those 2 new columns)
`imagedata` mediumblob NOT NULL,
`imagetype` varchar(100) NOT NULL default '',
In addlink.php find (set your max_height and max_width)
$link['linkurl'] = htmlspecialchars($link['linkurl']);
$link['catid'] = intval($link['catid']);
$link['keywords'] = clean_keywords($link['keywords']);
$errors = check_link_errors($link);
add after
$max_height = 500;
$max_width = 200;
if (is_uploaded_file($_FILES['linkimage']['tmp_name']))
{
$imagetype = trim(substr(strrchr(strtolower($_FILES['linkimage']['name']), '.'), 1));
if ($imagetype == "jpeg" OR $imagetype == "jpg" OR $imagetype == "png")
{
// Get new sizes
list($width, $height) = getimagesize($_FILES['linkimage']['tmp_name']);
$new_width = $width;
$new_height = $height;
if ($height > $max_height) {
$new_width = ($max_height / $height) * $width;
$new_height = $max_height;
}
if ($width > $max_width) {
$new_height = ($max_width / $width) * $height;
$new_width = $max_width;
}
$imagedata = imagecreatetruecolor($new_width, $new_height);
}
if ($imagetype == 'jpeg' OR $imagetype == 'jpg')
{
$source = imagecreatefromjpeg($_FILES['linkimage']['tmp_name']);
imagecopyresampled($imagedata, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
ob_start();
imagejpeg($imagedata);
$imagedata = ob_get_contents();
ob_end_clean();
}
elseif ($imagetype == 'gif')
{
$imagedata = file_get_contents($_FILES['linkimage']['tmp_name']);
}
elseif ($imagetype == 'png')
{
$source = imagecreatefrompng($_FILES['linkimage']['tmp_name']);
imagecopyresampled($imagedata, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
ob_start();
imagepng($imagedata);
$imagedata = ob_get_contents();
ob_end_clean();
}
else
{
$imagedata = "";
$imagetype = "";
}
if (!empty($imagedata) AND !empty($imagetype))
{
$imagesql = ", imagedata = '" . addslashes($imagedata) . "', imagetype = '$imagetype'";
}
}
else
{
$imagedata = "";
$imagetype = "";
$imagesql = "";
}
find $newlink['description'] = htmlspecialchars($newlink['description']);
$newlink['linkurl'] = htmlspecialchars(trim($newlink['linkurl']));
$newlink['keywords'] = clean_keywords($newlink['keywords']);
$newlink['catid'] = intval($newlink['catid']);
$errors = check_link_errors($newlink);
add
$max_height = 500;
$max_width = 200;
if (is_uploaded_file($_FILES['linkimage']['tmp_name']))
{
$imagetype = trim(substr(strrchr(strtolower($_FILES['linkimage']['name']), '.'), 1));
if ($imagetype == "jpeg" OR $imagetype == "jpg" OR $imagetype == "png")
{
// Get new sizes
list($width, $height) = getimagesize($_FILES['linkimage']['tmp_name']);
$new_width = $width;
$new_height = $height;
if ($height > $max_height) {
$new_width = ($max_height / $height) * $width;
$new_height = $max_height;
}
if ($width > $max_width) {
$new_height = ($max_width / $width) * $height;
$new_width = $max_width;
}
$imagedata = imagecreatetruecolor($new_width, $new_height);
}
if ($imagetype == 'jpeg' OR $imagetype == 'jpg')
{
$source = imagecreatefromjpeg($_FILES['linkimage']['tmp_name']);
imagecopyresampled($imagedata, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
ob_start();
imagejpeg($imagedata);
$imagedata = ob_get_contents();
ob_end_clean();
}
elseif ($imagetype == 'gif')
{
$imagedata = file_get_contents($_FILES['linkimage']['tmp_name']);
}
elseif ($imagetype == 'png')
{
$source = imagecreatefrompng($_FILES['linkimage']['tmp_name']);
imagecopyresampled($imagedata, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
ob_start();
imagepng($imagedata);
$imagedata = ob_get_contents();
ob_end_clean();
}
else
{
$imagedata = "";
$imagetype = "";
}
if (!empty($imagedata) AND !empty($imagetype))
{
$imagesql = ", imagedata = '" . addslashes($imagedata) . "', imagetype = '$imagetype'";
}
}
else
{
$imagedata = "";
$imagetype = "";
$imagesql = "";
}
still in addlink.php locate the below and do the changes in red
$db->query_write("
INSERT INTO " . TABLE_PREFIX . "adv_links
(catid, name, linkurl, description, keywords, linkrecipurl, valid, open, username, userid, dateline, ipaddress, imagedata, imagetype)
VALUES (
$link[catid],
'" . $db->escape_string($link['name']) . "',
'" . $db->escape_string($link['linkurl']) . "',
'" . $db->escape_string($link['description']) . "',
'" . $db->escape_string($link['keywords']) . "',
'" . $db->escape_string($link['linkrecipurl']) . "',
$valid,
1,
'" . $db->escape_string($vbulletin->userinfo['username']) . "',
" . $vbulletin->userinfo['userid'] . ",
" . TIMENOW . ",
'" . $db->escape_string(IPADDRESS) . "',
'" . addslashes($imagedata) . "', '$imagetype'
)");
[$db->query_write("
UPDATE " . TABLE_PREFIX . "adv_links SET
catid = $newlink[catid],
name = '" . $db->escape_string($newlink['name']) . "',
linkurl = '" . $db->escape_string($newlink['linkurl']) . "',
linkrecipurl = '" . $db->escape_string($newlink['linkrecipurl']) . "',
description = '" . $db->escape_string($newlink['description']) . "',
keywords = '" . $db->escape_string($newlink['keywords']) . "',
lastupdated = " . TIMENOW . ",
notes = '" . $db->escape_string($newlink['notes']) . "' $imagesql
WHERE linkid = $linkid
");
###################################################
in showlink.php after
if (empty($_REQUEST['do']))
{
$_REQUEST['do'] = 'showlink';
}
put
// ############################### Get Image ###############################
if ($_REQUEST['do'] == 'getimage')
{
$linkid = iif(is_numeric($_GET['linkid']), $_GET['linkid'], 0);
$imageinfo = $db->query_first("
SELECT imagedata, imagetype
FROM " . TABLE_PREFIX . "adv_links
WHERE linkid = '$linkid'
");
if ($linkid)
{
header('Cache-control: max-age=31536000');
header('Expires: ' . gmdate('D, d M Y H:i:s', (TIMENOW + 31536000)) . ' GMT');
header('Content-disposition: inline; filename=image.jpg');
header('Content-transfer-encoding: binary');
header('Content-Length: ' . strlen($imageinfo['imagedata']));
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', (TIMENOW)) . ' GMT');
$extension = $imageinfo['imagetype'];
if ($extension == 'jpg' OR $extension == 'jpeg')
{
header('Content-type: image/jpeg');
}
else if ($extension == 'png')
{
header('Content-type: image/png');
}
else
{
header('Content-type: image/gif');
}
print $imageinfo['imagedata'];
}
die();
}
#########################################
templates changes
ADV_LINKS_ADD_EDIT change the form action to
<form enctype="multipart/form-data" action="addlink.php" method="post">
after the $customfieldbits, put in the upload form
<fieldset class="fieldset"><legend>Link Image</legend>
<div style="padding:$stylevar[formspacer]px">
Upload an image (or change current one)<br />jpg or png will be resized to 300 pixels width if larger.<br />Gif images <b>must</b> be 300 px wide or under or image will be deleted.<br />
<input class="bginput" name="linkimage" size="40" type="file" />
</div>
</fieldset>
in ADV_LINKS_SHOWLINK (now use your imagination where you want image to display. My template has been reworked completely, so you have to figure it out, it's just plain HTML
<if condition="!empty($link[imagedata])">
<img style="padding: 0px" src="showlink.php?$session[sessionurl]do=getimage&linkid=$link[linkid]" />
</if>
Sorry guys, instructions are a little messy, I am in a hurry. I have this installed for a while now and I just wanted to share.
Alter table_prefix adv_links (use phpadmin to add those 2 new columns)
`imagedata` mediumblob NOT NULL,
`imagetype` varchar(100) NOT NULL default '',
In addlink.php find (set your max_height and max_width)
$link['linkurl'] = htmlspecialchars($link['linkurl']);
$link['catid'] = intval($link['catid']);
$link['keywords'] = clean_keywords($link['keywords']);
$errors = check_link_errors($link);
add after
$max_height = 500;
$max_width = 200;
if (is_uploaded_file($_FILES['linkimage']['tmp_name']))
{
$imagetype = trim(substr(strrchr(strtolower($_FILES['linkimage']['name']), '.'), 1));
if ($imagetype == "jpeg" OR $imagetype == "jpg" OR $imagetype == "png")
{
// Get new sizes
list($width, $height) = getimagesize($_FILES['linkimage']['tmp_name']);
$new_width = $width;
$new_height = $height;
if ($height > $max_height) {
$new_width = ($max_height / $height) * $width;
$new_height = $max_height;
}
if ($width > $max_width) {
$new_height = ($max_width / $width) * $height;
$new_width = $max_width;
}
$imagedata = imagecreatetruecolor($new_width, $new_height);
}
if ($imagetype == 'jpeg' OR $imagetype == 'jpg')
{
$source = imagecreatefromjpeg($_FILES['linkimage']['tmp_name']);
imagecopyresampled($imagedata, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
ob_start();
imagejpeg($imagedata);
$imagedata = ob_get_contents();
ob_end_clean();
}
elseif ($imagetype == 'gif')
{
$imagedata = file_get_contents($_FILES['linkimage']['tmp_name']);
}
elseif ($imagetype == 'png')
{
$source = imagecreatefrompng($_FILES['linkimage']['tmp_name']);
imagecopyresampled($imagedata, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
ob_start();
imagepng($imagedata);
$imagedata = ob_get_contents();
ob_end_clean();
}
else
{
$imagedata = "";
$imagetype = "";
}
if (!empty($imagedata) AND !empty($imagetype))
{
$imagesql = ", imagedata = '" . addslashes($imagedata) . "', imagetype = '$imagetype'";
}
}
else
{
$imagedata = "";
$imagetype = "";
$imagesql = "";
}
find $newlink['description'] = htmlspecialchars($newlink['description']);
$newlink['linkurl'] = htmlspecialchars(trim($newlink['linkurl']));
$newlink['keywords'] = clean_keywords($newlink['keywords']);
$newlink['catid'] = intval($newlink['catid']);
$errors = check_link_errors($newlink);
add
$max_height = 500;
$max_width = 200;
if (is_uploaded_file($_FILES['linkimage']['tmp_name']))
{
$imagetype = trim(substr(strrchr(strtolower($_FILES['linkimage']['name']), '.'), 1));
if ($imagetype == "jpeg" OR $imagetype == "jpg" OR $imagetype == "png")
{
// Get new sizes
list($width, $height) = getimagesize($_FILES['linkimage']['tmp_name']);
$new_width = $width;
$new_height = $height;
if ($height > $max_height) {
$new_width = ($max_height / $height) * $width;
$new_height = $max_height;
}
if ($width > $max_width) {
$new_height = ($max_width / $width) * $height;
$new_width = $max_width;
}
$imagedata = imagecreatetruecolor($new_width, $new_height);
}
if ($imagetype == 'jpeg' OR $imagetype == 'jpg')
{
$source = imagecreatefromjpeg($_FILES['linkimage']['tmp_name']);
imagecopyresampled($imagedata, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
ob_start();
imagejpeg($imagedata);
$imagedata = ob_get_contents();
ob_end_clean();
}
elseif ($imagetype == 'gif')
{
$imagedata = file_get_contents($_FILES['linkimage']['tmp_name']);
}
elseif ($imagetype == 'png')
{
$source = imagecreatefrompng($_FILES['linkimage']['tmp_name']);
imagecopyresampled($imagedata, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
ob_start();
imagepng($imagedata);
$imagedata = ob_get_contents();
ob_end_clean();
}
else
{
$imagedata = "";
$imagetype = "";
}
if (!empty($imagedata) AND !empty($imagetype))
{
$imagesql = ", imagedata = '" . addslashes($imagedata) . "', imagetype = '$imagetype'";
}
}
else
{
$imagedata = "";
$imagetype = "";
$imagesql = "";
}
still in addlink.php locate the below and do the changes in red
$db->query_write("
INSERT INTO " . TABLE_PREFIX . "adv_links
(catid, name, linkurl, description, keywords, linkrecipurl, valid, open, username, userid, dateline, ipaddress, imagedata, imagetype)
VALUES (
$link[catid],
'" . $db->escape_string($link['name']) . "',
'" . $db->escape_string($link['linkurl']) . "',
'" . $db->escape_string($link['description']) . "',
'" . $db->escape_string($link['keywords']) . "',
'" . $db->escape_string($link['linkrecipurl']) . "',
$valid,
1,
'" . $db->escape_string($vbulletin->userinfo['username']) . "',
" . $vbulletin->userinfo['userid'] . ",
" . TIMENOW . ",
'" . $db->escape_string(IPADDRESS) . "',
'" . addslashes($imagedata) . "', '$imagetype'
)");
[$db->query_write("
UPDATE " . TABLE_PREFIX . "adv_links SET
catid = $newlink[catid],
name = '" . $db->escape_string($newlink['name']) . "',
linkurl = '" . $db->escape_string($newlink['linkurl']) . "',
linkrecipurl = '" . $db->escape_string($newlink['linkrecipurl']) . "',
description = '" . $db->escape_string($newlink['description']) . "',
keywords = '" . $db->escape_string($newlink['keywords']) . "',
lastupdated = " . TIMENOW . ",
notes = '" . $db->escape_string($newlink['notes']) . "' $imagesql
WHERE linkid = $linkid
");
###################################################
in showlink.php after
if (empty($_REQUEST['do']))
{
$_REQUEST['do'] = 'showlink';
}
put
// ############################### Get Image ###############################
if ($_REQUEST['do'] == 'getimage')
{
$linkid = iif(is_numeric($_GET['linkid']), $_GET['linkid'], 0);
$imageinfo = $db->query_first("
SELECT imagedata, imagetype
FROM " . TABLE_PREFIX . "adv_links
WHERE linkid = '$linkid'
");
if ($linkid)
{
header('Cache-control: max-age=31536000');
header('Expires: ' . gmdate('D, d M Y H:i:s', (TIMENOW + 31536000)) . ' GMT');
header('Content-disposition: inline; filename=image.jpg');
header('Content-transfer-encoding: binary');
header('Content-Length: ' . strlen($imageinfo['imagedata']));
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', (TIMENOW)) . ' GMT');
$extension = $imageinfo['imagetype'];
if ($extension == 'jpg' OR $extension == 'jpeg')
{
header('Content-type: image/jpeg');
}
else if ($extension == 'png')
{
header('Content-type: image/png');
}
else
{
header('Content-type: image/gif');
}
print $imageinfo['imagedata'];
}
die();
}
#########################################
templates changes
ADV_LINKS_ADD_EDIT change the form action to
<form enctype="multipart/form-data" action="addlink.php" method="post">
after the $customfieldbits, put in the upload form
<fieldset class="fieldset"><legend>Link Image</legend>
<div style="padding:$stylevar[formspacer]px">
Upload an image (or change current one)<br />jpg or png will be resized to 300 pixels width if larger.<br />Gif images <b>must</b> be 300 px wide or under or image will be deleted.<br />
<input class="bginput" name="linkimage" size="40" type="file" />
</div>
</fieldset>
in ADV_LINKS_SHOWLINK (now use your imagination where you want image to display. My template has been reworked completely, so you have to figure it out, it's just plain HTML
<if condition="!empty($link[imagedata])">
<img style="padding: 0px" src="showlink.php?$session[sessionurl]do=getimage&linkid=$link[linkid]" />
</if>