Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Showing images with GD

Status
Not open for further replies.

jon159785

IS-IT--Management
Jul 8, 2003
15
US
I'm attempting to write a script that will show images, but also do some database work. If i omit the 'require_once' to connect to the database it works fine, but when I have that in there it gives me an error. How can I connect to the database and still have the images show?

Thanks for your help,

<?php
require_once('../../mysql_connect_pictures.php');
// The file
$filename = 'league.jpg';
$percent = 0.5;

// Content type
header('Content-type: image/jpeg');

// Get new dimensions
list($width, $height) = getimagesize($filename);
$new_width = $width * $percent;
$new_height = $height * $percent;

// Resample
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

// Output
imagejpeg($image_p, null, 100);
?>

Warning: Cannot modify header information - headers already sent by (output started at etc...Pictures/picturetest.php on line 10
 
The [tt]header()[/tt] must parsed before any PHP code -(be the first line in your PHP file).

Let's know if it works now.

Best Regards


Jakob
 
Moving it to the top doesn't produce the error, but it still doesn't work. That's what's throwing me for a loop.


<?php
header('Content-type: image/jpeg');

require_once('../../mysql_connect_pictures.php');

// The file
$filename = 'league.jpg';
$percent = 0.5;

etc...... ?>

ÿØÿàJFIFÿþ<CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality = 100
ÿÛCÿÛCÿÀp"ÿÄ
ÿĵ}!1AQa"q2?‘¡#B±ÁRÑð$3br‚
%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyzƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖ×ØÙÚáâãäåæçèéêñòóôõö÷øùúÿÄ
ÿÄ
 
Is it case-sensitive? Try [highlight white][tt]Content-[red]T[/red]ype[/tt][/highlight]

--Chessbot

"In that blessed region of Four Dimensions, shall we linger on the threshold of the Fifth, and not enter therein? Ah, no! [...] Then, yielding to our intellectual onset, the gates of the Sixth Dimension shall fly open; after that a Seventh, and then an Eighth -- --" Flatland, A. Square (E. A. Abbott)
 
Woops [ponder]

That post of yours got all messed up!!

Remember to wrap your code in [tt][ignore][[/ignore]code[ignore]] ... your code ... [[/ignore]/code[ignore]][/ignore][/tt] according to
However, one thing springs to mind:

Try
Code:
require_once('../mysql_connect_pictures.php');
in stead of
Code:
require_once('../../mysql_connect_pictures.php');

... or go with an absolute path like
Code:
require_once('/apache/docroot/mysql_connect_pictures.php');

Remember that PHP deals with absolute paths; not (web) server paths!

Regards


Jakob
 
ops... sorry for coding that...

No luck with the capitalization... and I know I'm pointing to the right file as I do get this error if I don't.

Code:
<b>Warning</b>:  main(../mysql_connect_pictures.php): failed to open stream: No such file or directory in <b>/

Any other ideas?
 
Then try

Code:
$new_width = (int) $width * $percent;
$new_height = (int) $height * $percent;

... just to make sure sizes are integer ...

Regards


Jakob
 
maybe I should fill in some more background here... I had a gd script working just fine... then I switched to a new host.. it didn't work, now I'm trying to trouble shoot it. I just noticed that if I try and log into my site with a log in, I get this error:

Code:
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/nojjond/mysql_connect_pictures.php:17) in /home/nojjond/public_html/Pictures/login.php on line 49

Warning: Cannot modify header information - headers already sent by (output started at /home/nojjond/mysql_connect_pictures.php:17) in /home/nojjond/public_html/Pictures/login.php on line 51

Would that indicate I possibly have a larger problem then just getting GD to work?

Thanks for your help.
 
Seem like mysql_connect_pictures.php too is parsing a header. Have a look at your class(es)/functions in mysql_connect_pictures.php to see if you can remove/replace the header in there.

Regards


Jakob
 
Still no luck. This is what I have in mysql_connect_pictures.php:

Code:
<?php
$dbc=mysql_connect ("localhost", "MYUSERNAME", "MYPASSWORD") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("nojjond_dbpictures"); 
?>

Is it possible there is some setting on the server that is not allowing headers to be used correctly?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top