|
Posted by Ciaran on 08/27/07 13:17
Hi can someone please help me with this? It was all working perfectly until
yesterday! I haven't changed anything so I presume it's something my web
host is updating.
I'm getting the following errors now and the uploaded image does not save:
Warning: Cannot modify header information - headers already sent by (output
started at /home/scout/public_html/0scripts/photopost.php:1) in
/home/scout/public_html/0scripts/getfunctions.php on line 177
Warning: imagejpeg() [function.imagejpeg]: Unable to open
'photos/ScenesPhotography_9.jpg' for writing in
/home/scout/public_html/0scripts/getfunctions.php on line 201
Here's the saving functions:
function saveimage($thefile,$thefilepath,$thewidth,$theheight){
//setup & get vars:::::
$thefile=$_FILES[$thefile];
$max_size = 2000000; //2MB
if (!isset($thefile)){ echo "NO FILE!!!"; return false;} //failsafe for
blank images
echo "<b>Uploading file:</B> ".$thefile['name']."
".($thefile['size']/1000)." KB";
if (is_uploaded_file($thefile['tmp_name'])) {
if ($thefile['size']>$max_size) { echo "The file is too big<br/>\n";
return false; }
if (($thefile['type']=="image/pjpeg") ||
($thefile['type']=="image/jpeg")){
if (file_exists($thefilepath)) { echo "...overwriting old file"; }
//resize and save the image to the path specified on the server:::::::
$res = resizeimage($thewidth,$theheight,$thefile['tmp_name'],
$thefilepath);
if (!$res) { echo "...upload failed!"; return false; } else { echo
"...ALL DONE!"; }
} else { echo '<h6>...File type not allowed!</h6>You may need to convert
your images to ready them for the web.'; return false; }
} else { echo "...no file;"; return false;}
return true;
}//upload function
//RESIZES JPEGS (RUN BY SAVEIMAGE FUNCTION)::::::::::::
function resizeimage( $forcedwidth, $forcedheight, $sourcefile, $destfile )
{
echo "...resizing image";
// Content type
header('Content-type: image/jpeg');
// Get new dimensions
list($oldwidth, $oldheight) = getimagesize($sourcefile);
if($oldwidth>$forcedwidth || $oldheight>$forcedheight){//if image is larger
than forced sizes:
$ratio=$forcedwidth/$oldwidth;
$newheight=$ratio*$oldheight;
$newwidth=$ratio*$oldwidth;
//check against forcedheight:
if($newheight>$forcedheight){
$ratio=$forcedheight/$newheight;
$newwidth*=$ratio;
$newheight*=$ratio;
}
}else{//if image is smaller than forced sizes:
$newwidth=$oldwidth;
$newheight=$oldheight;
}
// Resample
$image_p = imagecreatetruecolor($newwidth, $newheight);
$image = imagecreatefromjpeg($sourcefile);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $newwidth, $newheight,
$oldwidth, $oldheight);
// Output
imagejpeg($image_p, $destfile, 85);
echo "...complete!...";
echo "<img src='$destfile' height='65'>";
return true;
}
Navigation:
[Reply to this message]
|