I am trying to set the header('Content-Type: image/jpeg');
in one of my files called resizeImage.php (I'm following the tutorial from http://php.net/manual/en/function.imagecopyresampled.php). And I kept getting this error: Warning: Cannot modify header information - headers already sent by (output started at /home/sites/aejhyun.com/public_html/Syrian Project/index.php:557)
. So I did some research and stumbled upon a very good post called How to fix "Headers already sent" error in PHP and looked at http://www.w3schools.com/php/func_http_header.asp. I tried doing what the tutorials told me to do but none of them worked.
To give you some context my resizeImage.php
code is this:
<?php
$directory = "uploads/";
$images = glob($directory."*.jpeg");
header('Content-Type: image/jpeg');
foreach($images as $filename) {
// Set a maximum height and width
$width = 200;
$height = 200;
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
$ratio_orig = $width_orig/$height_orig;
if ($width/$height > $ratio_orig) {
$width = $height*$ratio_orig;
} else {
$height = $width/$ratio_orig;
}
// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output
imagejpeg($image_p, null, 100);
}
?>
I kept getting the error, I tried adding ob_start()
to my php file but that still caused the error. I tried erasing header('Content-Type: image/jpeg');
from my php file and I tried adding it all the way to the top of my index.php
file like so:
<?php
header('Content-Type: image/jpeg');
?>
<!doctype html>
But that caused all my content on my website to disappear with a picture error icon showing all the way in the left corner. Like so:
Anybody know how to fix this problem?