PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi, Before listing my problem I would excuse for my English... because i am not a native english speaker
I am trying to read an image from the client side and read the contents of the images through
When I try put the header("Content-type:image/jpeg"); line then it says that header already sent error message.
When I try to avoid this i use ob_start() and ob_flush() to display the image, but it only prints the URL from the address bar of the browser. But if I send header("Location:someotherpage.php"); It works well
So Is there any solution for this problem to display the Images header inside the html page
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
aftabnaveed wrote:When I try put the header("Content-type:image/jpeg"); line then it says that header already sent error message.
And it tells you the file:line where the output occurred. Please mark that line in your code.
Now I am trying to display Image inside a table like
<table>
<tr>
<td><?php
header("Content-type:image/jpeg");
echo($content);
?>
</td>
</tr>
</table>
Images in html are referenced as <img src="....">. You must not print the binary image data within the html document. (there's a small exception to this rule, but it's negligible)
Printing the URL when you use Content-type:image/jpeg means that the $content does not contain valid jpeg image. if you view the source of the page on which you get this error you will see what is the problem, but i guess it is the HTML code after the echo.
It breaks the JPEG and makes it invalid for displayng.
As for as header information is concernd i am trying to display the image on line 169 of my html document
and one other thing i have experiments my code in a seprate file before i have been sending any header in any form and it worked for me well,,, So the Question arises that How can I send multiple headers in php. I have user ob_start() and ob_flush() functions but it didn't worked for me at all The Code which successfully executed is
but the above code is for testing purpose in a seprate file thats why i have tried to use it also in html
here is the header error: Warning: Cannot modify header information - headers already sent by (output started at F:\wamp\www\realestate\includes\application_top.php:18) in F:\wamp\www\realestate\includes\pages\modules\members\forsale\view_forsale.php on line 169
aftabnaveed wrote:So the Question arises that How can I send multiple headers in php.
You can't if what you are trying to do is first tell the browser that the page is text/HTML and then you're trying to tell it that it's an image instead. That's why if you want an image to display in a webpage you need to use the IMG tag. You can do the following:
i.e. you can call a PHP script in the src attribute if you need to process the image with PHP before displaying it (and in that file - myphpimagescript.php - you would set the headers to be image headers).
I don't wana save the file on my server, I want to show the user the preview of the I mages then if he/she wants to save the i mage then it will be saved on the server.
So Please help me on retrieving the temperory file will be thankful to you guys
you must save it on your server first, then display it.
For this purpose you can make temp directory which saves the files and if the user decides to save it when he see it you will move it from temp directory to the proper location.
You will ask now what will be happen with the files in the temp folder if user decides to not save the image. Yea their number will grow fast, but you can run a cron which checks the file timestamps and if older than 1 day -> unlink()
Don't forget to check the file before accept it in the temp folder, chekcing the extension or mime type is not enough. You can use the GD lib to check the images with imagecreatefromjpeg if this returns false this means the file is not jpeg even its extension is jpg
Thanks for your suggession I totaly understand what you are saying,, but what if the Server I am hosting my site is Windows Server
and, Cron also have a version for windows what if its not installed there....
Please guide me if i am saying some thing wrong
On windows servers the crons are called sheduled tasks. If you don't have access to set up it, you can put the checking code in the same file which uploads the image, so when someone tries to upload image the script will do the cleaning procedure.