I want to show an image and wrote below codes
$path = "C:\xampp\htdocs\me\1.jpg";
$image1 = imagecreatefromjpeg($path);
header('Content-Type: image/jpeg');
imagejpeg($image1);
But when I run it in Firefox it shows:
The image
“http://127.0.0.1/me/Untitled%201.php”
cannot be displayed because it
contains errors.
What is problem?
Edit:
I deleted header function but it has this error:
Warning: imagecreatefromjpeg(C:
mpp\htdocs\me.jpg)
[function.imagecreatefromjpeg]: failed
to open stream: Invalid argument in
C:\xampp\htdocs\me\Untitled 1.php on
line 136Warning: imagejpeg() expects parameter 1 to be resource, boolean
given in C:\xampp\htdocs\me\Untitled
1.php on line 138
after all works it shows some chars like this
$.' ",#(7),01444'9=82<.342ÿÛC 2!!22222222222222222222222222222222222222222222222222ÿÀ¸)"ÿÄ ÿĵ}!1AQa"q2‘¡#B±ÁRÑð$3br‚ %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyzƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖרÙÚáâãäåæçèéêñòóôõö÷øùúÿÄ ÿĵw!1AQaq"2B‘¡±Á #3RðbrÑ $4á%ñ&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz‚ƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖרÙÚâãäåæçèéêòóôõö÷øùúÿÚ?ùþŠ( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š
In this specific case, you forgot to escape the backslashes
\in the file path. Either use escaped backslashes\\or – much better – forward slashes:/To debug stuff like this, remove the
header()line to see the image’s source code to see the PHP error messages that are breaking it.