Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 9th, 2006, 05:33 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 347
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Adam H-W
Default basic addition to php

I just need to add the following code to this page above where the image is drawn: I need to add <a href:javascript:history.go(-1) but I'm not sure where it goes - can any one help? here is the code for the page

<?php

require_once("config.php");

// path being dynamically requested
if(!empty($_REQUEST['src'])) {
    if(file_exists(stripslashes(PATH.$_REQUEST['src'])))
        $src = urldecode(stripslashes(PATH.$_REQUEST['src']));
    else
        $src = null;

    // extra validation
    $src = stristr($src, '..') ? null : $src;
}

// see if we're working with a thumbnail or not
$size = !empty($_REQUEST['size']) && $_REQUEST['size'] == 'full' ? $_REQUEST['size'] : null;

// draw watermarked & thumbnail images
function draw_image($src) {
    global $size;
    list($width, $height, $type, $attr) = getimagesize($src);
    $img = imagecreatefromstring(file_get_contents($src));


    if($size == 'full') {
        $red = imagecolorallocate($img, 0xFF, 0x00, 0x00);
        imagestring($img, 5, 3, 3, WATERMARK, $red);
    } else {
        $lowest = min(THMBWIDTH / $width, THMBHEIGHT / $height);
        if($lowest < 1) {
            $smallwidth = floor($lowest*$width);
            $smallheight = floor($lowest*$height);
            $tmp = imagecreatetruecolor($smallwidth, $smallheight);
            imagecopyresized($tmp, $img, 0, 0, 0, 0, $smallwidth, $smallheight, $width, $height);
            imagedestroy($img);
            $img = $tmp;
        }
    }

    switch($type) {
        case 1:
        header("Content-type: image/gif");
        imagegif($img);
        break;

        case 2:
        header('Content-Type: image/jpeg');
        imagejpeg($img, '', 100);
        break;

        case 3:
        header("Content-type: image/png");
        imagepng($img);
        break;
    }
    imagedestroy($img);
}

if(!empty($src)) {
    draw_image($src);

} else {
    header("Content-type: image/png");
    $img = imagecreatetruecolor(THMBWIDTH, THMBHEIGHT);
    $black = imagecolorallocate($img, 0x00, 0x00, 0x00);
    $white = imagecolorallocate($img, 0xFF, 0xFF, 0xFF);
    imagestring($img, 5, 3, 3, "NO IMAGE", $white);
    imagepng($img);
    imagedestroy($img);
}

?>

thanks

Adam

 
Old June 9th, 2006, 09:08 AM
Authorized User
 
Join Date: May 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to guillermo
Default

I guess you should put the following in your 'draw_image' function, right above your switch statement:

print '<a href="javascript:history.go(-1);">Some Text</a>';

That should print right before the image is created. If I'm misunderstanding your question, let me know.


 
Old June 10th, 2006, 03:36 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 347
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Adam H-W
Default

thanks again Guillermo!

 
Old July 10th, 2006, 09:58 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 347
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Adam H-W
Default

Hi,

I'm getting the following error in my script:

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING

with this code:

$print '<a href="javascript:history.go(-1);">Back</a>';


Can anyone tell me where I'm going wrong?

thanks

Adam






Similar Threads
Thread Thread Starter Forum Replies Last Post
Hexadecimal Addition madanshah16 XSLT 1 July 31st, 2007 07:21 AM
Addition of Textboxes rhd110 General .NET 3 June 23rd, 2007 04:49 PM
Addition in javascript m_soni21 VBScript 2 December 19th, 2006 11:06 AM
addition to errata luciano991 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 August 25th, 2006 08:29 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.