Spudhead
06-11-2007, 12:14 PM
<?php
$parameters = array('axis', 'size', 'file');
foreach($parameters as $name){
$$name = isset($_GET[$name]) ? $_GET[$name] : '';
}
$root = realpath(@$_SERVER['DOCUMENT_ROOT']);
$filesroot = str_replace ("\\files", "\\_files", $root ) . "\\";
$path = $filesroot.$file;
$image = imagecreatefromjpeg($path);
if ($image){
// Get image size and scale ratio
$oldwidth = imagesx($image);
$oldheight = imagesy($image);
if ($axis == 'x'){
$newwidth = $size;
$newheight = floor(($newwidth * $oldheight) / $oldwidth);
}elseif ($axis == 'y'){
$newheight = $size;
$newwidth = floor(($newheight * $oldwidth) / $oldheight);
}
// create new image
$tmp_img = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($tmp_img, $image, 0, 0, 0, 0, $newwidth, $newheight, $oldwidth, $oldheight);
//write to file
ImageJPEG($tmp_img, $filesroot.$axis.$size."_".$file, 80);
imagedestroy ($tmp_img);
imagedestroy($image);
}
//header("Location: http://www.mysite.com/files/files.asp");
?>
This is the first fully-functioning PHP script I've written so apologies if it's a bit of a daft question, but - what's writing HTTP headers there? If I uncomment the header() line at the end I get a "headers already written" error, but I don't see anything there that should be sending output back down to the browser?
Assuming that something is, and that's what it's supposed to be doing, and I've just misunderstood what it's doing - how can I get this script to redirect somewhere once it's finished creating me some images?
$parameters = array('axis', 'size', 'file');
foreach($parameters as $name){
$$name = isset($_GET[$name]) ? $_GET[$name] : '';
}
$root = realpath(@$_SERVER['DOCUMENT_ROOT']);
$filesroot = str_replace ("\\files", "\\_files", $root ) . "\\";
$path = $filesroot.$file;
$image = imagecreatefromjpeg($path);
if ($image){
// Get image size and scale ratio
$oldwidth = imagesx($image);
$oldheight = imagesy($image);
if ($axis == 'x'){
$newwidth = $size;
$newheight = floor(($newwidth * $oldheight) / $oldwidth);
}elseif ($axis == 'y'){
$newheight = $size;
$newwidth = floor(($newheight * $oldwidth) / $oldheight);
}
// create new image
$tmp_img = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($tmp_img, $image, 0, 0, 0, 0, $newwidth, $newheight, $oldwidth, $oldheight);
//write to file
ImageJPEG($tmp_img, $filesroot.$axis.$size."_".$file, 80);
imagedestroy ($tmp_img);
imagedestroy($image);
}
//header("Location: http://www.mysite.com/files/files.asp");
?>
This is the first fully-functioning PHP script I've written so apologies if it's a bit of a daft question, but - what's writing HTTP headers there? If I uncomment the header() line at the end I get a "headers already written" error, but I don't see anything there that should be sending output back down to the browser?
Assuming that something is, and that's what it's supposed to be doing, and I've just misunderstood what it's doing - how can I get this script to redirect somewhere once it's finished creating me some images?