Re: [PHP] Retrieving Image Location in PHP from MySQL
On Mon, Mar 9, 2009 at 8:43 PM, Sashikanth Gurram sashi...@vt.edu wrote: Is there any way in which I can assign a variable to a query string? Like for example, Let us say that there are two php files a.php and b.php. I am currently using a image tag like img src=imgtest.php?id=Williams Hall / in a.php and am passing the value to another variable using $build=$_GET['id']; in b.php. Now for this purpose, I am using the img tag in the html part of my first file which makes it kind of static. Now if I want to assign a variable (say $building) to 'id' in my first file, and retrieve it using the variable $build in the second file what is the best way to do it? Will the command (written inside the PHP tags) echo ' img src=imgtest.php?id=$building /'; be of any help in performing the task. I have actually tried this out, but it did not work for me (May be my syntax is wrong although I have tried various combinations). So, is there a better way or correct way of doing this (If what I have done is wrong). I have tried to use $_session() command, but it is kind of yielding me a header error. I'm not sure if this has been addressed in any of the other replies, but I felt it was worth mentioning: Be careful and pay attention to whether you are using single quotes ( ' ) or double quotes ( ) in your echo statements! $var = 'asdf'; echo 'hey, $var'; // hey, $var echo hey, $var; // hey, asdf ...and if you're using single or double quotes elsewhere (i.e., assignment operations)... $var = 'asdf'; $othervar = 'blah$var'; // blah$var $anothervar = blah$var; // blahasdf $yetanothervar = blah{$var}blah; // blahasdfblah Double quotes, when not using echo, can still parse variables for you. -- // Todd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Retrieving Image Location in PHP from MySQL
haliphax wrote: On Mon, Mar 9, 2009 at 8:43 PM, Sashikanth Gurram sashi...@vt.edu wrote: Is there any way in which I can assign a variable to a query string? Like for example, Let us say that there are two php files a.php and b.php. I am currently using a image tag like img src=imgtest.php?id=Williams Hall / in a.php and am passing the value to another variable using $build=$_GET['id']; in b.php. Now for this purpose, I am using the img tag in the html part of my first file which makes it kind of static. Now if I want to assign a variable (say $building) to 'id' in my first file, and retrieve it using the variable $build in the second file what is the best way to do it? Will the command (written inside the PHP tags) echo ' img src=imgtest.php?id=$building /'; be of any help in performing the task. I have actually tried this out, but it did not work for me (May be my syntax is wrong although I have tried various combinations). So, is there a better way or correct way of doing this (If what I have done is wrong). I have tried to use $_session() command, but it is kind of yielding me a header error. I'm not sure if this has been addressed in any of the other replies, but I felt it was worth mentioning: Be careful and pay attention to whether you are using single quotes ( ' ) or double quotes ( ) in your echo statements! $var = 'asdf'; echo 'hey, $var'; // hey, $var echo hey, $var; // hey, asdf ...and if you're using single or double quotes elsewhere (i.e., assignment operations)... $var = 'asdf'; $othervar = 'blah$var'; // blah$var $anothervar = blah$var; // blahasdf $yetanothervar = blah{$var}blah; // blahasdfblah Double quotes, when not using echo, can still parse variables for you. Thanks, Haliphax. I knew this stuff from janet valede's PHP for dummies. -Sashi -- ~ ~ Sashikanth Gurram Graduate Research Assistant Department of Civil and Environmental Engineering Virginia Tech Blacksburg, VA 24060, USA -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Retrieving Image Location in PHP from MySQL
Hi Nathan, Thanks a lot for the suggestion. It is working fine for an example code I have used to test it. The code I have written after your suggestion is as follows. ?php $location=C:\wamp\bin\apache\apache2.2.8\htdocs\Bldgs_lots\SQUIRES.jpg; header('Content-Type: image/jpeg'); imagejpeg(imagecreatefromjpeg($location)); ? The above code is yielding me a picture. Now, When I tried to use it in my original code it is not giving me the image. Instead it is giving me this warning *Warning*: Cannot modify header information - headers already sent by (output started at C:\wamp\www\mysqli.php:65) in *C:\wamp\www\mysqli.php* on line *221* and a lot binary characters again instead of the image. I know something about this warning that we should not output anything to the browser before the header. But I cannot do that, since I need the user input using a html form and I use the input to fetch the data and dispaly it in a table along with the image. I am posting the whole code below. Please do let me know about any changes, corrections or modifications that are needed. The image display code is towards the last. Thanks, Sashi html body form action=mysqli.php method=post br div align=center Building Name:select name=name option value= Select a Building/option option value=Williams HallWilliams Hall/option option value=Women's Softball FieldWomen's Softball Field/option option value=Wright HouseWright House/option /select /div input type=submit / /form ?php // Connects to your Database $host=*; $user=*; $password=*; $dbname=*; $cxn=mysqli_connect($host, $user, $password, $dbname) ; if (!$cxn=mysqli_connect($host, $user, $password, $dbname)) { $error=mysqli_error($cxn); echo $error; die(); } else { echo Connection established successfully; } //Define the variables for Day and Month $Today=date(l); $Month=date(F); $build=$_POST[name]; $low_speed=2.5; $high_speed=4; $hour=date(G); $minute=date(i); if ($minute=00 $minute=14) { $minute=00; } elseif ($minute=15 $minute=29) { $minute=15; } elseif ($minute=30 $minute=44) { $minute=30; } else { $minute=45; } $times=10:$minute; $sql=SELECT buildingname, parking_lot_name, empty_spaces, distance, round(distance/($low_speed*60),1) AS low_time, round(distance/($high_speed*60),1) AS high_time, Location FROM buildings, buildings_lots, parkinglots, occupancy2, Image where (buildings.buildingcode=occupancy2.building AND buildings.buildingcode=buildings_lots.building_code AND parkinglots.parking_lot_code=buildings_lots.parking_lot_code AND parkinglots.parking_lot_code=occupancy2.parking_lot AND Buildings.BuildingCode=Image.BuildingCode) AND buildingname='$build' AND month='$Month' AND day='Monday' AND Time='$times'; $data = mysqli_query($cxn,$sql); if (!$data=mysqli_query($cxn,$sql)) { $error=mysqli_error($cxn); echo $error; die(); } else { echo br; echo Query sent successfully; } echo br; echo h1 PARKING LOT INFORMATION h1; echo table border='1' cellspacing='5' cellpadding='2'; echo tr\n thBuilding/th\n thParking Lot/th\n thEstimated Number of Empty Spaces/th\n thDistance (Feet)/th\n thEstimated walking time to the building/th\n /tr\n; while ($row=mysqli_fetch_array($data)) { extract($row); $building = $row[0]; $parking_lot = $row[1]; $Number_of_Empty_Spaces = $row[2]; $Distance = $row[3]; $time_l = $row[4]; $time_h=$row[5]; $location=$row[6]; echo tr\n td$building/td\n td$parking_lot/td\n td$Number_of_Empty_Spaces/td\n td$Distance/td\n td$time_h - $time_l mins/td\n td$location/td\n /tr\n; } echo /table\n; header('Content-Type: image/jpeg'); imagejpeg(imagecreatefromjpeg($location)); ? /body /html Nathan Nobbe wrote: On Sat, Mar 7, 2009 at 9:36 PM, Sashikanth Gurram sashi...@vt.edu wrote: The thing is, I do not have a website or a place where I am storing my images. I am storing the images on my local PC in folder as mentioned in my earlier post. I have tried using only the else { header('Content-Type: image/jpeg'); imagejpeg($img); imagedestroy($img); } Which you have suggested. This is the piece of code which is returning all the binary character stuff. The code is definitely fetching the image. But it is not able to deliver to the browser in the form of an image. I am trying to read the image file as binary, evident from the FILE_BINARY command. So may be, that is causing the image to be displayed as binary. Is there any way we can convert the binary content to jpeg/jpg content again. This is my guess after having gone through the code again. i spent 2 minutes working on it and read this in the manual, the first param of imagejpeg(), An image resource, returned by one of the image creation functions, such as
Re: [PHP] Retrieving Image Location in PHP from MySQL
Hi Nathan, Thanks a lot for the suggestion. It is working fine for an example code I have used to test it. The code I have written after your suggestion is as follows. ?php $location=C:\wamp\bin\apache\apache2.2.8\htdocs\Bldgs_lots\SQUIRES.jpg; header('Content-Type: image/jpeg'); imagejpeg(imagecreatefromjpeg($location)); ? The above code is yielding me a picture. Now, When I tried to use it in my original code it is not giving me the image. Instead it is giving me this warning *Warning*: Cannot modify header information - headers already sent by (output started at C:\wamp\www\mysqli.php:65) in *C:\wamp\www\mysqli.php* on line *221* and a lot binary characters again instead of the image. I know something about this warning that we should not output anything to the browser before the header. But I cannot do that, since I need the user input using a html form and I use the input to fetch the data and dispaly it in a table along with the image. I am posting the whole code below. Please do let me know about any changes, corrections or modifications that are needed. The image display code is towards the last. Thanks, Sashi html body form action=mysqli.php method=post br div align=center Building Name:select name=name option value= Select a Building/option option value=Williams HallWilliams Hall/option option value=Women's Softball FieldWomen's Softball Field/option option value=Wright HouseWright House/option /select /div input type=submit / /form ?php // Connects to your Database $host=*; $user=*; $password=*; $dbname=*; $cxn=mysqli_connect($host, $user, $password, $dbname) ; if (!$cxn=mysqli_connect($host, $user, $password, $dbname)) { $error=mysqli_error($cxn); echo $error; die(); } else { echo Connection established successfully; } //Define the variables for Day and Month $Today=date(l); $Month=date(F); $build=$_POST[name]; $low_speed=2.5; $high_speed=4; $hour=date(G); $minute=date(i); if ($minute=00 $minute=14) { $minute=00; } elseif ($minute=15 $minute=29) { $minute=15; } elseif ($minute=30 $minute=44) { $minute=30; } else { $minute=45; } $times=10:$minute; $sql=SELECT buildingname, parking_lot_name, empty_spaces, distance, round(distance/($low_speed*60),1) AS low_time, round(distance/($high_speed*60),1) AS high_time, Location FROM buildings, buildings_lots, parkinglots, occupancy2, Image where (buildings.buildingcode=occupancy2.building AND buildings.buildingcode=buildings_lots.building_code AND parkinglots.parking_lot_code=buildings_lots.parking_lot_code AND parkinglots.parking_lot_code=occupancy2.parking_lot AND Buildings.BuildingCode=Image.BuildingCode) AND buildingname='$build' AND month='$Month' AND day='Monday' AND Time='$times'; $data = mysqli_query($cxn,$sql); if (!$data=mysqli_query($cxn,$sql)) { $error=mysqli_error($cxn); echo $error; die(); } else { echo br; echo Query sent successfully; } echo br; echo h1 PARKING LOT INFORMATION h1; echo table border='1' cellspacing='5' cellpadding='2'; echo tr\n thBuilding/th\n thParking Lot/th\n thEstimated Number of Empty Spaces/th\n thDistance (Feet)/th\n thEstimated walking time to the building/th\n /tr\n; while ($row=mysqli_fetch_array($data)) { extract($row); $building = $row[0]; $parking_lot = $row[1]; $Number_of_Empty_Spaces = $row[2]; $Distance = $row[3]; $time_l = $row[4]; $time_h=$row[5]; $location=$row[6]; echo tr\n td$building/td\n td$parking_lot/td\n td$Number_of_Empty_Spaces/td\n td$Distance/td\n td$time_h - $time_l mins/td\n td$location/td\n /tr\n; } echo /table\n; header('Content-Type: image/jpeg'); imagejpeg(imagecreatefromjpeg($location)); ? /body /html Nathan Nobbe wrote: On Sat, Mar 7, 2009 at 9:36 PM, Sashikanth Gurram sashi...@vt.edu wrote: The thing is, I do not have a website or a place where I am storing my images. I am storing the images on my local PC in folder as mentioned in my earlier post. I have tried using only the else { header('Content-Type: image/jpeg'); imagejpeg($img); imagedestroy($img); } Which you have suggested. This is the piece of code which is returning all the binary character stuff. The code is definitely fetching the image. But it is not able to deliver to the browser in the form of an image. I am trying to read the image file as binary, evident from the FILE_BINARY command. So may be, that is causing the image to be displayed as binary. Is there any way we can convert the binary content to jpeg/jpg content again. This is my guess after having gone through the code again. i spent 2 minutes working on it and read this in the manual, the first param of imagejpeg(), An image resource, returned by
Re: [PHP] Retrieving Image Location in PHP from MySQL
On Mon, Mar 9, 2009 at 1:29 AM, Sashikanth Gurram sashi...@vt.edu wrote: Hi Nathan, Thanks a lot for the suggestion. It is working fine for an example code I have used to test it. The code I have written after your suggestion is as follows. ?php $location=C:\wamp\bin\apache\apache2.2.8\htdocs\Bldgs_lots\SQUIRES.jpg; header('Content-Type: image/jpeg'); imagejpeg(imagecreatefromjpeg($location)); ? The above code is yielding me a picture. Now, When I tried to use it in my original code it is not giving me the image. Instead it is giving me this warning *Warning*: Cannot modify header information - headers already sent by (output started at C:\wamp\www\mysqli.php:65) in *C:\wamp\www\mysqli.php* on line *221* and a lot binary characters again instead of the image. I know something about this warning that we should not output anything to the browser before the header. But I cannot do that, since I need the user input using a html form and I use the input to fetch the data and dispaly it in a table along with the image. I am posting the whole code below. Please do let me know about any changes, corrections or modifications that are needed. The image display code is towards the last. Thanks, Sashi html body form action=mysqli.php method=post br div align=center Building Name:select name=name option value= Select a Building/option option value=Williams HallWilliams Hall/option option value=Women's Softball FieldWomen's Softball Field/option option value=Wright HouseWright House/option /select /div input type=submit / /form ?php // Connects to your Database $host=*; $user=*; $password=*; $dbname=*; $cxn=mysqli_connect($host, $user, $password, $dbname) ; if (!$cxn=mysqli_connect($host, $user, $password, $dbname)) { $error=mysqli_error($cxn); echo $error; die(); } else { echo Connection established successfully; } //Define the variables for Day and Month $Today=date(l); $Month=date(F); $build=$_POST[name]; $low_speed=2.5; $high_speed=4; $hour=date(G); $minute=date(i); if ($minute=00 $minute=14) { $minute=00; } elseif ($minute=15 $minute=29) { $minute=15; } elseif ($minute=30 $minute=44) { $minute=30; } else { $minute=45; } $times=10:$minute; $sql=SELECT buildingname, parking_lot_name, empty_spaces, distance, round(distance/($low_speed*60),1) AS low_time, round(distance/($high_speed*60),1) AS high_time, Location FROM buildings, buildings_lots, parkinglots, occupancy2, Image where (buildings.buildingcode=occupancy2.building AND buildings.buildingcode=buildings_lots.building_code AND parkinglots.parking_lot_code=buildings_lots.parking_lot_code AND parkinglots.parking_lot_code=occupancy2.parking_lot AND Buildings.BuildingCode=Image.BuildingCode) AND buildingname='$build' AND month='$Month' AND day='Monday' AND Time='$times'; $data = mysqli_query($cxn,$sql); if (!$data=mysqli_query($cxn,$sql)) { $error=mysqli_error($cxn); echo $error; die(); } else { echo br; echo Query sent successfully; } echo br; echo h1 PARKING LOT INFORMATION h1; echo table border='1' cellspacing='5' cellpadding='2'; echo tr\n thBuilding/th\n thParking Lot/th\n thEstimated Number of Empty Spaces/th\n thDistance (Feet)/th\n thEstimated walking time to the building/th\n /tr\n; while ($row=mysqli_fetch_array($data)) { extract($row); $building = $row[0]; $parking_lot = $row[1]; $Number_of_Empty_Spaces = $row[2]; $Distance = $row[3]; $time_l = $row[4]; $time_h=$row[5]; $location=$row[6]; echo tr\n td$building/td\n td$parking_lot/td\n td$Number_of_Empty_Spaces/td\n td$Distance/td\n td$time_h - $time_l mins/td\n td$location/td\n /tr\n; } echo /table\n; header('Content-Type: image/jpeg'); imagejpeg(imagecreatefromjpeg($location)); ? /body /html Nathan Nobbe wrote: On Sat, Mar 7, 2009 at 9:36 PM, Sashikanth Gurram sashi...@vt.edu wrote: The thing is, I do not have a website or a place where I am storing my images. I am storing the images on my local PC in folder as mentioned in my earlier post. I have tried using only the else { header('Content-Type: image/jpeg'); imagejpeg($img); imagedestroy($img); } Which you have suggested. This is the piece of code which is returning all the binary character stuff. The code is definitely fetching the image. But it is not able to deliver to the browser in the form of an image. I am trying to read the image file as binary, evident from the FILE_BINARY command. So may be, that is causing the image to be displayed as binary. Is there any way we can convert the binary content to jpeg/jpg content again. This is my guess after having gone through the code again.
Re: [PHP] Retrieving Image Location in PHP from MySQL
On Sun, Mar 8, 2009 at 11:29 PM, Sashikanth Gurram sashi...@vt.edu wrote: Hi Nathan, Thanks a lot for the suggestion. It is working fine for an example code I have used to test it. The code I have written after your suggestion is as follows. ?php $location=C:\wamp\bin\apache\apache2.2.8\htdocs\Bldgs_lots\SQUIRES.jpg; header('Content-Type: image/jpeg'); imagejpeg(imagecreatefromjpeg($location)); ? The above code is yielding me a picture. Now, When I tried to use it in my original code it is not giving me the image. Instead it is giving me this warning *Warning*: Cannot modify header information - headers already sent by (output started at C:\wamp\www\mysqli.php:65) in *C:\wamp\www\mysqli.php* on line *221* read the manual on header(), http://us.php.net/header youve probly echo'd some output to the browser prior to calling header(). -nathan
Re: [PHP] Retrieving Image Location in PHP from MySQL
Hi, Yes, the problem was solved, but It did not work fine when I used the same code in my larger file. Now it makes sense. Let me just repeat what you have said just to make sure that I did not misread you. So you say that the solution to this problem is to create another php file with the image fetching header and just write an img tag img src=myimagescript.php?id=1234 / in my original php file (with the html tags). This is what I have understood. Regarding the point you have mentioned ( If you set the content type using header() to image/jpeg, do not use HTML tags to display your image!), I definitely need the HTML tags, because this application works based on the user input. So unless there is not input through a html form, it wont work. Thanks, Sashi On Mon, Mar 9, 2009 at 1:29 AM, Sashikanth Gurram sashi...@vt.edu wrote: Hi Nathan, Thanks a lot for the suggestion. It is working fine for an example code I have used to test it. The code I have written after your suggestion is as follows. ?php $location=C:\wamp\bin\apache\apache2.2.8\htdocs\Bldgs_lots\SQUIRES.jpg; header('Content-Type: image/jpeg'); imagejpeg(imagecreatefromjpeg($location)); ? The above code is yielding me a picture. Now, When I tried to use it in my original code it is not giving me the image. Instead it is giving me this warning *Warning*: Cannot modify header information - headers already sent by (output started at C:\wamp\www\mysqli.php:65) in *C:\wamp\www\mysqli.php* on line *221* and a lot binary characters again instead of the image. I know something about this warning that we should not output anything to the browser before the header. But I cannot do that, since I need the user input using a html form and I use the input to fetch the data and dispaly it in a table along with the image. I am posting the whole code below. Please do let me know about any changes, corrections or modifications that are needed. The image display code is towards the last. Thanks, Sashi html body form action=mysqli.php method=post br div align=center Building Name:select name=name option value= Select a Building/option option value=Williams HallWilliams Hall/option option value=Women's Softball FieldWomen's Softball Field/option option value=Wright HouseWright House/option /select /div input type=submit / /form ?php // Connects to your Database $host=*; $user=*; $password=*; $dbname=*; $cxn=mysqli_connect($host, $user, $password, $dbname) ; if (!$cxn=mysqli_connect($host, $user, $password, $dbname)) { $error=mysqli_error($cxn); echo $error; die(); } else { echo Connection established successfully; } //Define the variables for Day and Month $Today=date(l); $Month=date(F); $build=$_POST[name]; $low_speed=2.5; $high_speed=4; $hour=date(G); $minute=date(i); if ($minute=00 $minute=14) { $minute=00; } elseif ($minute=15 $minute=29) { $minute=15; } elseif ($minute=30 $minute=44) { $minute=30; } else { $minute=45; } $times=10:$minute; $sql=SELECT buildingname, parking_lot_name, empty_spaces, distance, round(distance/($low_speed*60),1) AS low_time, round(distance/($high_speed*60),1) AS high_time, Location FROM buildings, buildings_lots, parkinglots, occupancy2, Image where (buildings.buildingcode=occupancy2.building AND buildings.buildingcode=buildings_lots.building_code AND parkinglots.parking_lot_code=buildings_lots.parking_lot_code AND parkinglots.parking_lot_code=occupancy2.parking_lot AND Buildings.BuildingCode=Image.BuildingCode) AND buildingname='$build' AND month='$Month' AND day='Monday' AND Time='$times'; $data = mysqli_query($cxn,$sql); if (!$data=mysqli_query($cxn,$sql)) { $error=mysqli_error($cxn); echo $error; die(); } else { echo br; echo Query sent successfully; } echo br; echo h1 PARKING LOT INFORMATION h1; echo table border='1' cellspacing='5' cellpadding='2'; echo tr\n thBuilding/th\n thParking Lot/th\n thEstimated Number of Empty Spaces/th\n thDistance (Feet)/th\n thEstimated walking time to the building/th\n /tr\n; while ($row=mysqli_fetch_array($data)) { extract($row); $building = $row[0]; $parking_lot = $row[1]; $Number_of_Empty_Spaces = $row[2]; $Distance = $row[3]; $time_l = $row[4]; $time_h=$row[5]; $location=$row[6]; echo tr\n td$building/td\n td$parking_lot/td\n td$Number_of_Empty_Spaces/td\n td$Distance/td\n td$time_h - $time_l mins/td\n td$location/td\n /tr\n; } echo /table\n; header('Content-Type: image/jpeg'); imagejpeg(imagecreatefromjpeg($location)); ? /body /html Nathan Nobbe wrote: On Sat, Mar 7, 2009 at 9:36 PM, Sashikanth Gurram sashi...@vt.edu wrote: The thing is, I do not have a website or a place where I am storing my images. I am storing the images on my local PC in folder as
Re: [PHP] Retrieving Image Location in PHP from MySQL
I am using a WAMP server for my coding purposes. My MySQL Version is 5.0.51b, PHP version is 5.2.6 and Apache version is 2.2.8 I have created a database with one of the tables containing a location of the image. Using PHP I am trying to retrieve the location of the image (from the mysql db) and display it in a browser. I have, with help from php-db mailing list user's help, created a code to do the same. Now, the problem is, the code is extracting the location details of the image exactly and it is even getting the image details. But it is simply not dispalying the image. Instead of displaying the image, it is printing a hell lot of binary characters (For example: 2! !22ÿÀ ^ ÿÄ ÿĵ } !1A Qa q 2 ‘¡ #B±Á RÑð$3br‚ %'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyzƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖ×ØÙÚáâãäåæçèéêñòóôõö÷øùúÿÄ ÿĵ w !1 AQ aq 2 B‘¡±Á #3Rð brÑ $4á%ñ '()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz‚ƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤) I have tried in two forums and mailing lists but none of them have completely answered my question. How do I get rid of these signs and display the original image in its place? And to display the image successfully, is it really necessary to create the image retrieval and displaying code in a seperate PHP file? Any PHP gurus, enthusiasts, newbies out there, Please help me out. I am posting the code below so that you can directly see what I have done till now. The name of the php file is mysqli.php. The location of the image is stored to the variable $location. The image retrieval code is present towards end of the file. Thanks, Sashi html body form action=mysqli.php method=post br div align=center Building Name:select name=name option value= Select a Building/option option value=Williams HallWilliams Hall/option option value=Women's Softball FieldWomen's Softball Field/option option value=Wright HouseWright House/option /select /div input type=submit / /form ?php // Connects to your Database $host=***; $user=***; $password=***; $dbname=***; $cxn=mysqli_connect($host, $user, $password, $dbname) ; if (!$cxn=mysqli_connect($host, $user, $password, $dbname)) { $error=mysqli_error($cxn); echo $error; die(); } else { echo Connection established successfully; } //Define the variables for Day and Month $Today=date(l); $Month=date(F); $build=$_POST[name]; $low_speed=2.5; $high_speed=4; $hour=date(G); $minute=date(i); if ($minute=00 $minute=14) { $minute=00; } elseif ($minute=15 $minute=29) { $minute=15; } elseif ($minute=30 $minute=44) { $minute=30; } else { $minute=45; } $times=$hour:$minute; $sql=SELECT buildingname, parking_lot_name, empty_spaces, distance, round(distance/($low_speed*60),1) AS low_time, round(distance/($high_speed*60),1) AS high_time, Location FROM buildings, buildings_lots, parkinglots, occupancy2, Image where (buildings.buildingcode=occupancy2.building AND buildings.buildingcode=buildings_lots.building_code AND parkinglots.parking_lot_code=buildings_lots.parking_lot_code AND parkinglots.parking_lot_code=occupancy2.parking_lot AND Buildings.BuildingCode=Image.BuildingCode) AND buildingname='$build' AND month='$Month' AND day='$Today' AND Time='$times'; $data = mysqli_query($cxn,$sql); if (!$data=mysqli_query($cxn,$sql)) { $error=mysqli_error($cxn); echo $error; die(); } else { echo br; echo Query sent successfully; } echo br; echo h1 PARKING LOT INFORMATION h1; echo table border='1' cellspacing='5' cellpadding='2'; echo tr\n thBuilding/th\n thParking Lot/th\n thEstimated Number of Empty Spaces/th\n thDistance (Feet)/th\n thEstimated walking time to the building/th\n /tr\n; while ($row=mysqli_fetch_array($data)) { extract($row); $building = $row[0]; $parking_lot = $row[1]; $Number_of_Empty_Spaces = $row[2]; $Distance = $row[3]; $time_l = $row[4]; $time_h=$row[5]; $location=$row[6]; echo tr\n td$building/td\n td$parking_lot/td\n td$Number_of_Empty_Spaces/td\n td$Distance/td\n td$time_h - $time_l mins/td\n td$location/td\n /tr\n; } echo /table\n; $err=1; if ($img = file_get_contents($location, FILE_BINARY)) { if ($img = imagecreatefromstring($img)) $err = 0; } if ($err) { header('Content-Type: text/html'); echo 'htmlbodyp style=font-size:9pxError getting image.../p/body/html'; } else { header('Content-Type: image/jpeg'); imagejpeg($img); echo 'img src=mysqli.php?img=' . $location . ' border=1 height=150 width=200 alt=' . $build . ''; imagedestroy($img); } ? /body /html Hi Sashikanth, here is how to do it. change td$location/td\n into tdimg src='$location' /td\n then // to comment the useless php code. see the changes below: while ($row=mysqli_fetch_array($data)) { extract($row); $building = $row[0]; $parking_lot = $row[1]; $Number_of_Empty_Spaces =
Re: [PHP] Retrieving Image Location in PHP from MySQL
On Mon, Mar 9, 2009 at 9:32 AM, Sashikanth Gurram sashi...@vt.edu wrote: On Mon, Mar 9, 2009 at 1:29 AM, Sashikanth Gurram sashi...@vt.edu wrote: Hi Nathan, Thanks a lot for the suggestion. It is working fine for an example code I have used to test it. The code I have written after your suggestion is as follows. ?php $location=C:\wamp\bin\apache\apache2.2.8\htdocs\Bldgs_lots\SQUIRES.jpg; header('Content-Type: image/jpeg'); imagejpeg(imagecreatefromjpeg($location)); ? The above code is yielding me a picture. Now, When I tried to use it in my original code it is not giving me the image. Instead it is giving me this warning *Warning*: Cannot modify header information - headers already sent by (output started at C:\wamp\www\mysqli.php:65) in *C:\wamp\www\mysqli.php* on line *221* and a lot binary characters again instead of the image. I know something about this warning that we should not output anything to the browser before the header. But I cannot do that, since I need the user input using a html form and I use the input to fetch the data and dispaly it in a table along with the image. I am posting the whole code below. Please do let me know about any changes, corrections or modifications that are needed. The image display code is towards the last. html body form action=mysqli.php method=post br div align=center Building Name:select name=name option value= Select a Building/option option value=Williams HallWilliams Hall/option option value=Women's Softball FieldWomen's Softball Field/option option value=Wright HouseWright House/option /select /div input type=submit / /form ?php // Connects to your Database $host=*; $user=*; $password=*; $dbname=*; $cxn=mysqli_connect($host, $user, $password, $dbname) ; if (!$cxn=mysqli_connect($host, $user, $password, $dbname)) { $error=mysqli_error($cxn); echo $error; die(); } else { echo Connection established successfully; } //Define the variables for Day and Month $Today=date(l); $Month=date(F); $build=$_POST[name]; $low_speed=2.5; $high_speed=4; $hour=date(G); $minute=date(i); if ($minute=00 $minute=14) { $minute=00; } elseif ($minute=15 $minute=29) { $minute=15; } elseif ($minute=30 $minute=44) { $minute=30; } else { $minute=45; } $times=10:$minute; $sql=SELECT buildingname, parking_lot_name, empty_spaces, distance, round(distance/($low_speed*60),1) AS low_time, round(distance/($high_speed*60),1) AS high_time, Location FROM buildings, buildings_lots, parkinglots, occupancy2, Image where (buildings.buildingcode=occupancy2.building AND buildings.buildingcode=buildings_lots.building_code AND parkinglots.parking_lot_code=buildings_lots.parking_lot_code AND parkinglots.parking_lot_code=occupancy2.parking_lot AND Buildings.BuildingCode=Image.BuildingCode) AND buildingname='$build' AND month='$Month' AND day='Monday' AND Time='$times'; $data = mysqli_query($cxn,$sql); if (!$data=mysqli_query($cxn,$sql)) { $error=mysqli_error($cxn); echo $error; die(); } else { echo br; echo Query sent successfully; } echo br; echo h1 PARKING LOT INFORMATION h1; echo table border='1' cellspacing='5' cellpadding='2'; echo tr\n thBuilding/th\n thParking Lot/th\n thEstimated Number of Empty Spaces/th\n thDistance (Feet)/th\n thEstimated walking time to the building/th\n /tr\n; while ($row=mysqli_fetch_array($data)) { extract($row); $building = $row[0]; $parking_lot = $row[1]; $Number_of_Empty_Spaces = $row[2]; $Distance = $row[3]; $time_l = $row[4]; $time_h=$row[5]; $location=$row[6]; echo tr\n td$building/td\n td$parking_lot/td\n td$Number_of_Empty_Spaces/td\n td$Distance/td\n td$time_h - $time_l mins/td\n td$location/td\n /tr\n; } echo /table\n; header('Content-Type: image/jpeg'); imagejpeg(imagecreatefromjpeg($location)); ? /body /html Nathan Nobbe wrote: On Sat, Mar 7, 2009 at 9:36 PM, Sashikanth Gurram sashi...@vt.edu wrote: The thing is, I do not have a website or a place where I am storing my images. I am storing the images on my local PC in folder as mentioned in my earlier post. I have tried using only the else { header('Content-Type: image/jpeg'); imagejpeg($img); imagedestroy($img); } Which you have suggested. This is the piece of code which is returning all the binary character stuff. The code is definitely fetching the image. But it is not able to deliver to the browser in the form of an image. I am trying to read the image file as binary, evident from the FILE_BINARY command. So may be, that is causing the image to be displayed as binary. Is there any way we can convert the binary content to jpeg/jpg content again. This is my guess after having gone through the
Re: [PHP] Retrieving Image Location in PHP from MySQL
On Mon, Mar 9, 2009 at 7:32 AM, Sashikanth Gurram sashi...@vt.edu wrote: Hi, Yes, the problem was solved, but It did not work fine when I used the same code in my larger file. Now it makes sense. right, just track down where you started sending the output, and remember if youre going to use header() calls in your scripts, that all of them must come before sending any of the standard content. Let me just repeat what you have said just to make sure that I did not misread you. So you say that the solution to this problem is to create another php file with the image fetching header and just write an img tag img src=myimagescript.php?id=1234 / in my original php file (with the html tags). what i explained in my first response is that youre mixing 2 different approaches, and it was unclear what you were going for exactly. if you want to have an image included in a page of html, then theres no need for the header() call (refer to my first response for the remaining details). there are however legitimate use cases for the use of header() the aforementioned image methods, i think between mine and some of the other posts on this thread, its explained clearly. This is what I have understood. Regarding the point you have mentioned ( If you set the content type using header() to image/jpeg, do not use HTML tags to display your image!), correct I definitely need the HTML tags, because this application works based on the user input. So unless there is not input through a html form, it wont work. right, then just configure your webserver such that you can first access the image directly via an http url, then integrate these links into your dynamic pages as i explained in my first response. good luck, -nathan
Re: [PHP] Retrieving Image Location in PHP from MySQL
Hi, Thanks a lot for all the patient replies. All the suggestions led me in a positive direction. Finally, instead of using the header() in my main PHP file (with HTML tags), I have used it in a secondary file and called it using a tagimg src=imgtest.php. It is working fine. But, the image I need to display is also dynamic and needs a user input. So, is there any way in which I can transfer a particular variable (the user input) from my main php file (say A.php) to my secondary file containing the header () (say B.php) Thanks, Sashi Nathan Nobbe wrote: On Mon, Mar 9, 2009 at 7:32 AM, Sashikanth Gurram sashi...@vt.edu mailto:sashi...@vt.edu wrote: Hi, Yes, the problem was solved, but It did not work fine when I used the same code in my larger file. Now it makes sense. right, just track down where you started sending the output, and remember if youre going to use header() calls in your scripts, that all of them must come before sending any of the standard content. Let me just repeat what you have said just to make sure that I did not misread you. So you say that the solution to this problem is to create another php file with the image fetching header and just write an img tag img src=myimagescript.php?id=1234 / in my original php file (with the html tags). what i explained in my first response is that youre mixing 2 different approaches, and it was unclear what you were going for exactly. if you want to have an image included in a page of html, then theres no need for the header() call (refer to my first response for the remaining details). there are however legitimate use cases for the use of header() the aforementioned image methods, i think between mine and some of the other posts on this thread, its explained clearly. This is what I have understood. Regarding the point you have mentioned ( If you set the content type using header() to image/jpeg, do not use HTML tags to display your image!), correct I definitely need the HTML tags, because this application works based on the user input. So unless there is not input through a html form, it wont work. right, then just configure your webserver such that you can first access the image directly via an http url, then integrate these links into your dynamic pages as i explained in my first response. good luck, -nathan -- ~ ~ Sashikanth Gurram Graduate Research Assistant Department of Civil and Environmental Engineering Virginia Tech Blacksburg, VA 24060, USA -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Retrieving Image Location in PHP from MySQL
From: Sashikanth Gurram Hi, Thanks a lot for all the patient replies. All the suggestions led me in a positive direction. Finally, instead of using the header() in my main PHP file (with HTML tags), I have used it in a secondary file and called it using a tagimg src=imgtest.php. It is working fine. But, the image I need to display is also dynamic and needs a user input. So, is there any way in which I can transfer a particular variable (the user input) from my main php file (say A.php) to my secondary file containing the header () (say B.php) Well, you are really trying to use one page to do two different tasks. First to display the input form, then to show an image selected by that input. So, either you need two code paths, or two pages. You can start off by checking the input fields and if they are empty, simply display the form. Then the next time through, when the fields are populated, insert the selected image. Bob McConnell -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Retrieving Image Location in PHP from MySQL
On Mon, Mar 9, 2009 at 10:24 AM, Sashikanth Gurram sashi...@vt.edu wrote: Nathan Nobbe wrote: On Mon, Mar 9, 2009 at 7:32 AM, Sashikanth Gurram sashi...@vt.edu mailto:sashi...@vt.edu wrote: Hi, Yes, the problem was solved, but It did not work fine when I used the same code in my larger file. Now it makes sense. right, just track down where you started sending the output, and remember if youre going to use header() calls in your scripts, that all of them must come before sending any of the standard content. Let me just repeat what you have said just to make sure that I did not misread you. So you say that the solution to this problem is to create another php file with the image fetching header and just write an img tag img src=myimagescript.php?id=1234 / in my original php file (with the html tags). what i explained in my first response is that youre mixing 2 different approaches, and it was unclear what you were going for exactly. if you want to have an image included in a page of html, then theres no need for the header() call (refer to my first response for the remaining details). there are however legitimate use cases for the use of header() the aforementioned image methods, i think between mine and some of the other posts on this thread, its explained clearly. This is what I have understood. Regarding the point you have mentioned ( If you set the content type using header() to image/jpeg, do not use HTML tags to display your image!), correct I definitely need the HTML tags, because this application works based on the user input. So unless there is not input through a html form, it wont work. right, then just configure your webserver such that you can first access the image directly via an http url, then integrate these links into your dynamic pages as i explained in my first response. Thanks a lot for all the patient replies. All the suggestions led me in a positive direction. Finally, instead of using the header() in my main PHP file (with HTML tags), I have used it in a secondary file and called it using a tagimg src=imgtest.php. It is working fine. But, the image I need to display is also dynamic and needs a user input. So, is there any way in which I can transfer a particular variable (the user input) from my main php file (say A.php) to my secondary file containing the header () (say B.php) Yes. Use the Query String of your image-producing PHP script to pass values. If you had an image tag like this: img src=imagescript.php?id=1234 / Then you could grab the value of $_GET['id'] in your PHP script and react accordingly. HTH, -- // Todd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Retrieving Image Location in PHP from MySQL
Thanks a lot everyone, particularly Haliphax, Nathan, Virgilio and Bob. I will try it and will come back to you. Thanks, Sashi haliphax wrote: On Mon, Mar 9, 2009 at 10:24 AM, Sashikanth Gurram sashi...@vt.edu wrote: Nathan Nobbe wrote: On Mon, Mar 9, 2009 at 7:32 AM, Sashikanth Gurram sashi...@vt.edu mailto:sashi...@vt.edu wrote: Hi, Yes, the problem was solved, but It did not work fine when I used the same code in my larger file. Now it makes sense. right, just track down where you started sending the output, and remember if youre going to use header() calls in your scripts, that all of them must come before sending any of the standard content. Let me just repeat what you have said just to make sure that I did not misread you. So you say that the solution to this problem is to create another php file with the image fetching header and just write an img tag img src=myimagescript.php?id=1234 / in my original php file (with the html tags). what i explained in my first response is that youre mixing 2 different approaches, and it was unclear what you were going for exactly. if you want to have an image included in a page of html, then theres no need for the header() call (refer to my first response for the remaining details). there are however legitimate use cases for the use of header() the aforementioned image methods, i think between mine and some of the other posts on this thread, its explained clearly. This is what I have understood. Regarding the point you have mentioned ( If you set the content type using header() to image/jpeg, do not use HTML tags to display your image!), correct I definitely need the HTML tags, because this application works based on the user input. So unless there is not input through a html form, it wont work. right, then just configure your webserver such that you can first access the image directly via an http url, then integrate these links into your dynamic pages as i explained in my first response. Thanks a lot for all the patient replies. All the suggestions led me in a positive direction. Finally, instead of using the header() in my main PHP file (with HTML tags), I have used it in a secondary file and called it using a tagimg src=imgtest.php. It is working fine. But, the image I need to display is also dynamic and needs a user input. So, is there any way in which I can transfer a particular variable (the user input) from my main php file (say A.php) to my secondary file containing the header () (say B.php) Yes. Use the Query String of your image-producing PHP script to pass values. If you had an image tag like this: img src=imagescript.php?id=1234 / Then you could grab the value of $_GET['id'] in your PHP script and react accordingly. HTH, -- ~ ~ Sashikanth Gurram Graduate Research Assistant Department of Civil and Environmental Engineering Virginia Tech Blacksburg, VA 24060, USA -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Retrieving Image Location in PHP from MySQL
On Mon, Mar 9, 2009 at 10:52 AM, Sashikanth Gurram sashi...@vt.edu wrote: haliphax wrote: On Mon, Mar 9, 2009 at 10:24 AM, Sashikanth Gurram sashi...@vt.edu wrote: Nathan Nobbe wrote: On Mon, Mar 9, 2009 at 7:32 AM, Sashikanth Gurram sashi...@vt.edu mailto:sashi...@vt.edu wrote: Hi, Yes, the problem was solved, but It did not work fine when I used the same code in my larger file. Now it makes sense. right, just track down where you started sending the output, and remember if youre going to use header() calls in your scripts, that all of them must come before sending any of the standard content. Let me just repeat what you have said just to make sure that I did not misread you. So you say that the solution to this problem is to create another php file with the image fetching header and just write an img tag img src=myimagescript.php?id=1234 / in my original php file (with the html tags). what i explained in my first response is that youre mixing 2 different approaches, and it was unclear what you were going for exactly. if you want to have an image included in a page of html, then theres no need for the header() call (refer to my first response for the remaining details). there are however legitimate use cases for the use of header() the aforementioned image methods, i think between mine and some of the other posts on this thread, its explained clearly. This is what I have understood. Regarding the point you have mentioned ( If you set the content type using header() to image/jpeg, do not use HTML tags to display your image!), correct I definitely need the HTML tags, because this application works based on the user input. So unless there is not input through a html form, it wont work. right, then just configure your webserver such that you can first access the image directly via an http url, then integrate these links into your dynamic pages as i explained in my first response. Thanks a lot for all the patient replies. All the suggestions led me in a positive direction. Finally, instead of using the header() in my main PHP file (with HTML tags), I have used it in a secondary file and called it using a tagimg src=imgtest.php. It is working fine. But, the image I need to display is also dynamic and needs a user input. So, is there any way in which I can transfer a particular variable (the user input) from my main php file (say A.php) to my secondary file containing the header () (say B.php) Yes. Use the Query String of your image-producing PHP script to pass values. If you had an image tag like this: img src=imagescript.php?id=1234 / Then you could grab the value of $_GET['id'] in your PHP script and react accordingly. Thanks a lot everyone, particularly Haliphax, Nathan, Virgilio and Bob. I will try it and will come back to you. You're very welcome. This page [1] may help you get started. It's a bit dated, but the information still holds true today. 1. http://whn.vdhri.net/2005/10/how_to_use_the_query_string_in_php.html -- // Todd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Retrieving Image Location in PHP from MySQL
haliphax wrote: On Mon, Mar 9, 2009 at 10:52 AM, Sashikanth Gurram sashi...@vt.edu wrote: haliphax wrote: On Mon, Mar 9, 2009 at 10:24 AM, Sashikanth Gurram sashi...@vt.edu wrote: Nathan Nobbe wrote: On Mon, Mar 9, 2009 at 7:32 AM, Sashikanth Gurram sashi...@vt.edu mailto:sashi...@vt.edu wrote: Hi, Yes, the problem was solved, but It did not work fine when I used the same code in my larger file. Now it makes sense. right, just track down where you started sending the output, and remember if youre going to use header() calls in your scripts, that all of them must come before sending any of the standard content. Let me just repeat what you have said just to make sure that I did not misread you. So you say that the solution to this problem is to create another php file with the image fetching header and just write an img tag img src=myimagescript.php?id=1234 / in my original php file (with the html tags). what i explained in my first response is that youre mixing 2 different approaches, and it was unclear what you were going for exactly. if you want to have an image included in a page of html, then theres no need for the header() call (refer to my first response for the remaining details). there are however legitimate use cases for the use of header() the aforementioned image methods, i think between mine and some of the other posts on this thread, its explained clearly. This is what I have understood. Regarding the point you have mentioned ( If you set the content type using header() to image/jpeg, do not use HTML tags to display your image!), correct I definitely need the HTML tags, because this application works based on the user input. So unless there is not input through a html form, it wont work. right, then just configure your webserver such that you can first access the image directly via an http url, then integrate these links into your dynamic pages as i explained in my first response. Thanks a lot for all the patient replies. All the suggestions led me in a positive direction. Finally, instead of using the header() in my main PHP file (with HTML tags), I have used it in a secondary file and called it using a tagimg src=imgtest.php. It is working fine. But, the image I need to display is also dynamic and needs a user input. So, is there any way in which I can transfer a particular variable (the user input) from my main php file (say A.php) to my secondary file containing the header () (say B.php) Yes. Use the Query String of your image-producing PHP script to pass values. If you had an image tag like this: img src=imagescript.php?id=1234 / Then you could grab the value of $_GET['id'] in your PHP script and react accordingly. Thanks a lot everyone, particularly Haliphax, Nathan, Virgilio and Bob. I will try it and will come back to you. You're very welcome. This page [1] may help you get started. It's a bit dated, but the information still holds true today. 1. http://whn.vdhri.net/2005/10/how_to_use_the_query_string_in_php.html Hello everyone, Is there any way in which I can assign a variable to a query string? Like for example, Let us say that there are two php files a.php and b.php. I am currently using a image tag like img src=imgtest.php?id=Williams Hall / in a.php and am passing the value to another variable using $build=$_GET['id']; in b.php. Now for this purpose, I am using the img tag in the html part of my first file which makes it kind of static. Now if I want to assign a variable (say $building) to 'id' in my first file, and retrieve it using the variable $build in the second file what is the best way to do it? Will the command (written inside the PHP tags) echo ' img src=imgtest.php?id=$building /'; be of any help in performing the task. I have actually tried this out, but it did not work for me (May be my syntax is wrong although I have tried various combinations). So, is there a better way or correct way of doing this (If what I have done is wrong). I have tried to use $_session() command, but it is kind of yielding me a header error. Thanks, Sashi -- ~ ~ Sashikanth Gurram Graduate Research Assistant Department of Civil and Environmental Engineering Virginia Tech Blacksburg, VA 24060, USA -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Retrieving Image Location in PHP from MySQL
Sashikanth Gurram wrote: haliphax wrote: On Mon, Mar 9, 2009 at 10:52 AM, Sashikanth Gurram sashi...@vt.edu wrote: haliphax wrote: On Mon, Mar 9, 2009 at 10:24 AM, Sashikanth Gurram sashi...@vt.edu wrote: Nathan Nobbe wrote: On Mon, Mar 9, 2009 at 7:32 AM, Sashikanth Gurram sashi...@vt.edu mailto:sashi...@vt.edu wrote: Hi, Yes, the problem was solved, but It did not work fine when I used the same code in my larger file. Now it makes sense. right, just track down where you started sending the output, and remember if youre going to use header() calls in your scripts, that all of them must come before sending any of the standard content. Let me just repeat what you have said just to make sure that I did not misread you. So you say that the solution to this problem is to create another php file with the image fetching header and just write an img tag img src=myimagescript.php?id=1234 / in my original php file (with the html tags). what i explained in my first response is that youre mixing 2 different approaches, and it was unclear what you were going for exactly. if you want to have an image included in a page of html, then theres no need for the header() call (refer to my first response for the remaining details). there are however legitimate use cases for the use of header() the aforementioned image methods, i think between mine and some of the other posts on this thread, its explained clearly. This is what I have understood. Regarding the point you have mentioned ( If you set the content type using header() to image/jpeg, do not use HTML tags to display your image!), correct I definitely need the HTML tags, because this application works based on the user input. So unless there is not input through a html form, it wont work. right, then just configure your webserver such that you can first access the image directly via an http url, then integrate these links into your dynamic pages as i explained in my first response. Thanks a lot for all the patient replies. All the suggestions led me in a positive direction. Finally, instead of using the header() in my main PHP file (with HTML tags), I have used it in a secondary file and called it using a tagimg src=imgtest.php. It is working fine. But, the image I need to display is also dynamic and needs a user input. So, is there any way in which I can transfer a particular variable (the user input) from my main php file (say A.php) to my secondary file containing the header () (say B.php) Yes. Use the Query String of your image-producing PHP script to pass values. If you had an image tag like this: img src=imagescript.php?id=1234 / Then you could grab the value of $_GET['id'] in your PHP script and react accordingly. Thanks a lot everyone, particularly Haliphax, Nathan, Virgilio and Bob. I will try it and will come back to you. You're very welcome. This page [1] may help you get started. It's a bit dated, but the information still holds true today. 1. http://whn.vdhri.net/2005/10/how_to_use_the_query_string_in_php.html Hello everyone, Is there any way in which I can assign a variable to a query string? Like for example, Let us say that there are two php files a.php and b.php. I am currently using a image tag like img src=imgtest.php?id=Williams Hall / in a.php and am passing the value to another variable using $build=$_GET['id']; in b.php. Now for this purpose, I am using the img tag in the html part of my first file which makes it kind of static. Now if I want to assign a variable (say $building) to 'id' in my first file, and retrieve it using the variable $build in the second file what is the best way to do it? Will the command (written inside the PHP tags) echo ' img src=imgtest.php?id=$building /'; be of any help in performing the task. I have actually tried this out, but it did not work for me (May be my syntax is wrong although I have tried various combinations). So, is there a better way or correct way of doing this (If what I have done is wrong). I have tried to use $_session() command, but it is kind of yielding me a header error. Thanks, Sashi Either: 1. a.php img src=b.php?id=?php echo $building; ? / --or-- 2. a.php echo 'img src=b.php?id=' . $building .' /'; Then, whicher you choose above: b.php: $build = $_GET['id']; -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Retrieving Image Location in PHP from MySQL
Hi, Worked perfectly. Thank you very much. -Sashi Dollah Ihsan wrote: Hi, you are using single quotes like this? echo ' img src=imgtest.php?id=$building /'; single quotes will ignore that $building variable. Just concatenate it: echo 'img src=imgtest.php?id=' . $building . ''; or use double quotes: echo img src=\imgtest.php?id=$building\; It should work I think, sorry if it does not. On Tue, Mar 10, 2009 at 8:14 AM, Sashikanth Gurram sashi...@vt.edu wrote: Hello everyone, Is there any way in which I can assign a variable to a query string? Like for example, Let us say that there are two php files a.php and b.php. I am currently using a image tag like img src=imgtest.php?id=Williams Hall / in a.php and am passing the value to another variable using $build=$_GET['id']; in b.php. Now for this purpose, I am using the img tag in the html part of my first file which makes it kind of static. Now if I want to assign a variable (say $building) to 'id' in my first file, and retrieve it using the variable $build in the second file what is the best way to do it? Will the command (written inside the PHP tags) echo ' img src=imgtest.php?id=$building /'; be of any help in performing the task. I have actually tried this out, but it did not work for me (May be my syntax is wrong although I have tried various combinations). So, is there a better way or correct way of doing this (If what I have done is wrong). I have tried to use $_session() command, but it is kind of yielding me a header error. Thanks, Sashi -- ~ ~ Sashikanth Gurram Graduate Research Assistant Department of Civil and Environmental Engineering Virginia Tech Blacksburg, VA 24060, USA -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- ~ ~ Sashikanth Gurram Graduate Research Assistant Department of Civil and Environmental Engineering Virginia Tech Blacksburg, VA 24060, USA -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Retrieving Image Location in PHP from MySQL
Thanks Shawn and Dollah -Sashi Shawn McKenzie wrote: Sashikanth Gurram wrote: haliphax wrote: On Mon, Mar 9, 2009 at 10:52 AM, Sashikanth Gurram sashi...@vt.edu wrote: haliphax wrote: On Mon, Mar 9, 2009 at 10:24 AM, Sashikanth Gurram sashi...@vt.edu wrote: Nathan Nobbe wrote: On Mon, Mar 9, 2009 at 7:32 AM, Sashikanth Gurram sashi...@vt.edu mailto:sashi...@vt.edu wrote: Hi, Yes, the problem was solved, but It did not work fine when I used the same code in my larger file. Now it makes sense. right, just track down where you started sending the output, and remember if youre going to use header() calls in your scripts, that all of them must come before sending any of the standard content. Let me just repeat what you have said just to make sure that I did not misread you. So you say that the solution to this problem is to create another php file with the image fetching header and just write an img tag img src=myimagescript.php?id=1234 / in my original php file (with the html tags). what i explained in my first response is that youre mixing 2 different approaches, and it was unclear what you were going for exactly. if you want to have an image included in a page of html, then theres no need for the header() call (refer to my first response for the remaining details). there are however legitimate use cases for the use of header() the aforementioned image methods, i think between mine and some of the other posts on this thread, its explained clearly. This is what I have understood. Regarding the point you have mentioned ( If you set the content type using header() to image/jpeg, do not use HTML tags to display your image!), correct I definitely need the HTML tags, because this application works based on the user input. So unless there is not input through a html form, it wont work. right, then just configure your webserver such that you can first access the image directly via an http url, then integrate these links into your dynamic pages as i explained in my first response. Thanks a lot for all the patient replies. All the suggestions led me in a positive direction. Finally, instead of using the header() in my main PHP file (with HTML tags), I have used it in a secondary file and called it using a tagimg src=imgtest.php. It is working fine. But, the image I need to display is also dynamic and needs a user input. So, is there any way in which I can transfer a particular variable (the user input) from my main php file (say A.php) to my secondary file containing the header () (say B.php) Yes. Use the Query String of your image-producing PHP script to pass values. If you had an image tag like this: img src=imagescript.php?id=1234 / Then you could grab the value of $_GET['id'] in your PHP script and react accordingly. Thanks a lot everyone, particularly Haliphax, Nathan, Virgilio and Bob. I will try it and will come back to you. You're very welcome. This page [1] may help you get started. It's a bit dated, but the information still holds true today. 1. http://whn.vdhri.net/2005/10/how_to_use_the_query_string_in_php.html Hello everyone, Is there any way in which I can assign a variable to a query string? Like for example, Let us say that there are two php files a.php and b.php. I am currently using a image tag like img src=imgtest.php?id=Williams Hall / in a.php and am passing the value to another variable using $build=$_GET['id']; in b.php. Now for this purpose, I am using the img tag in the html part of my first file which makes it kind of static. Now if I want to assign a variable (say $building) to 'id' in my first file, and retrieve it using the variable $build in the second file what is the best way to do it? Will the command (written inside the PHP tags) echo ' img src=imgtest.php?id=$building /'; be of any help in performing the task. I have actually tried this out, but it did not work for me (May be my syntax is wrong although I have tried various combinations). So, is there a better way or correct way of doing this (If what I have done is wrong). I have tried to use $_session() command, but it is kind of yielding me a header error. Thanks, Sashi Either: 1. a.php img src=b.php?id=?php echo $building; ? / --or-- 2. a.php echo 'img src=b.php?id=' . $building .' /'; Then, whicher you choose above: b.php: $build = $_GET['id']; -- ~ ~ Sashikanth Gurram Graduate Research Assistant Department of Civil and Environmental Engineering Virginia Tech Blacksburg, VA 24060, USA -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Retrieving Image Location in PHP from MySQL
On Sat, Mar 7, 2009 at 7:10 PM, Sashikanth Gurram sashi...@vt.edu wrote: Hello everyone, I am using a WAMP server for my coding purposes. My MySQL Version is 5.0.51b, PHP version is 5.2.6 and Apache version is 2.2.8 I have created a database with one of the tables containing a location of the image. Using PHP I am trying to retrieve the location of the image (from the mysql db) and display it in a browser. I have, with help from php-db mailing list user's help, created a code to do the same. Now, the problem is, the code is extracting the location details of the image exactly and it is even getting the image details. But it is simply not dispalying the image. Instead of displaying the image, it is printing a hell lot of binary characters (For example: 2! !22ÿÀ ^ ÿÄ ÿĵ } !1A Qa q 2 ‘¡ #B±Á RÑð$3br‚ %'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyzƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖ×ØÙÚáâãäåæçèéêñòóôõö÷øùúÿÄ ÿĵ w !1 AQ aq 2 B‘¡±Á #3Rð brÑ $4á%ñ'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz‚ƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤) I have tried in two forums and mailing lists but none of them have completely answered my question. How do I get rid of these signs and display the original image in its place? And to display the image successfully, is it really necessary to create the image retrieval and displaying code in a seperate PHP file? Any PHP gurus, enthusiasts, newbies out there, Please help me out. I am posting the code below so that you can directly see what I have done till now. The name of the php file is mysqli.php. The location of the image is stored to the variable $location. The image retrieval code is present towards end of the file. Thanks, Sashi html body form action=mysqli.php method=post br div align=center Building Name:select name=name option value= Select a Building/option option value=Williams HallWilliams Hall/option option value=Women's Softball FieldWomen's Softball Field/option option value=Wright HouseWright House/option /select /div input type=submit / /form ?php // Connects to your Database $host=***; $user=***; $password=***; $dbname=***; $cxn=mysqli_connect($host, $user, $password, $dbname) ; if (!$cxn=mysqli_connect($host, $user, $password, $dbname)) { $error=mysqli_error($cxn); echo $error; die(); } else { echo Connection established successfully; } //Define the variables for Day and Month $Today=date(l); $Month=date(F); $build=$_POST[name]; $low_speed=2.5; $high_speed=4; $hour=date(G); $minute=date(i); if ($minute=00 $minute=14) { $minute=00; } elseif ($minute=15 $minute=29) { $minute=15; } elseif ($minute=30 $minute=44) { $minute=30; } else { $minute=45; } $times=$hour:$minute; $sql=SELECT buildingname, parking_lot_name, empty_spaces, distance, round(distance/($low_speed*60),1) AS low_time, round(distance/($high_speed*60),1) AS high_time, Location FROM buildings, buildings_lots, parkinglots, occupancy2, Image where (buildings.buildingcode=occupancy2.building AND buildings.buildingcode=buildings_lots.building_code AND parkinglots.parking_lot_code=buildings_lots.parking_lot_code AND parkinglots.parking_lot_code=occupancy2.parking_lot AND Buildings.BuildingCode=Image.BuildingCode) AND buildingname='$build' AND month='$Month' AND day='$Today' AND Time='$times'; $data = mysqli_query($cxn,$sql); if (!$data=mysqli_query($cxn,$sql)) { $error=mysqli_error($cxn); echo $error; die(); } else { echo br; echo Query sent successfully; } echo br; echo h1 PARKING LOT INFORMATION h1; echo table border='1' cellspacing='5' cellpadding='2'; echo tr\n thBuilding/th\n thParking Lot/th\n thEstimated Number of Empty Spaces/th\n thDistance (Feet)/th\n thEstimated walking time to the building/th\n /tr\n; while ($row=mysqli_fetch_array($data)) { extract($row); $building = $row[0]; $parking_lot = $row[1]; $Number_of_Empty_Spaces = $row[2]; $Distance = $row[3]; $time_l = $row[4]; $time_h=$row[5]; $location=$row[6]; echo tr\n td$building/td\n td$parking_lot/td\n td$Number_of_Empty_Spaces/td\n td$Distance/td\n td$time_h - $time_l mins/td\n td$location/td\n /tr\n; } echo /table\n; $err=1; if ($img = file_get_contents($location, FILE_BINARY)) { if ($img = imagecreatefromstring($img)) $err = 0; } if ($err) { header('Content-Type: text/html'); echo 'htmlbodyp style=font-size:9pxError getting image.../p/body/html'; } else { header('Content-Type: image/jpeg'); imagejpeg($img); echo 'img src=mysqli.php?img=' . $location . ' border=1 height=150 width=200 alt=' . $build . ''; imagedestroy($img); } ? /body /html how are you storing the image in the database? i believe youll want to make it a BLOB of some type. also, depending on the application, many folks prefer to just place images directly on the
Re: [PHP] Retrieving Image Location in PHP from MySQL
I am just storing the location of the image(as a varchar type), not the image itself. For example for a particular image, the location is stored as C:\wamp\bin\apache\apache2.2.8\htdocs\Bldgs_lots\Burruss.jpg -sashi Nathan Nobbe wrote: On Sat, Mar 7, 2009 at 7:10 PM, Sashikanth Gurram sashi...@vt.edu mailto:sashi...@vt.edu wrote: Hello everyone, I am using a WAMP server for my coding purposes. My MySQL Version is 5.0.51b, PHP version is 5.2.6 and Apache version is 2.2.8 I have created a database with one of the tables containing a location of the image. Using PHP I am trying to retrieve the location of the image (from the mysql db) and display it in a browser. I have, with help from php-db mailing list user's help, created a code to do the same. Now, the problem is, the code is extracting the location details of the image exactly and it is even getting the image details. But it is simply not dispalying the image. Instead of displaying the image, it is printing a hell lot of binary characters (For example: 2! !22ÿÀ ^ ÿÄ ÿĵ } !1A Qa q 2 ‘¡ #B±Á RÑð$3br‚ %'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyzƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖ×ØÙÚáâãäåæçèéêñòóôõö÷øùúÿÄ ÿĵ w !1 AQ aq 2 B‘¡±Á #3Rð brÑ $4á%ñ '()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz‚ƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤) I have tried in two forums and mailing lists but none of them have completely answered my question. How do I get rid of these signs and display the original image in its place? And to display the image successfully, is it really necessary to create the image retrieval and displaying code in a seperate PHP file? Any PHP gurus, enthusiasts, newbies out there, Please help me out. I am posting the code below so that you can directly see what I have done till now. The name of the php file is mysqli.php. The location of the image is stored to the variable $location. The image retrieval code is present towards end of the file. Thanks, Sashi html body form action=mysqli.php method=post br div align=center Building Name:select name=name option value= Select a Building/option option value=Williams HallWilliams Hall/option option value=Women's Softball FieldWomen's Softball Field/option option value=Wright HouseWright House/option /select /div input type=submit / /form ?php // Connects to your Database $host=***; $user=***; $password=***; $dbname=***; $cxn=mysqli_connect($host, $user, $password, $dbname) ; if (!$cxn=mysqli_connect($host, $user, $password, $dbname)) { $error=mysqli_error($cxn); echo $error; die(); } else { echo Connection established successfully; } //Define the variables for Day and Month $Today=date(l); $Month=date(F); $build=$_POST[name]; $low_speed=2.5; $high_speed=4; $hour=date(G); $minute=date(i); if ($minute=00 $minute=14) { $minute=00; } elseif ($minute=15 $minute=29) { $minute=15; } elseif ($minute=30 $minute=44) { $minute=30; } else { $minute=45; } $times=$hour:$minute; $sql=SELECT buildingname, parking_lot_name, empty_spaces, distance, round(distance/($low_speed*60),1) AS low_time, round(distance/($high_speed*60),1) AS high_time, Location FROM buildings, buildings_lots, parkinglots, occupancy2, Image where (buildings.buildingcode=occupancy2.building AND buildings.buildingcode=buildings_lots.building_code AND parkinglots.parking_lot_code=buildings_lots.parking_lot_code AND parkinglots.parking_lot_code=occupancy2.parking_lot AND Buildings.BuildingCode=Image.BuildingCode) AND buildingname='$build' AND month='$Month' AND day='$Today' AND Time='$times'; $data = mysqli_query($cxn,$sql); if (!$data=mysqli_query($cxn,$sql)) { $error=mysqli_error($cxn); echo $error; die(); } else { echo br; echo Query sent successfully; } echo br; echo h1 PARKING LOT INFORMATION h1; echo table border='1' cellspacing='5' cellpadding='2'; echo tr\n thBuilding/th\n thParking Lot/th\n thEstimated Number of Empty Spaces/th\n thDistance (Feet)/th\n thEstimated walking time to the building/th\n /tr\n; while ($row=mysqli_fetch_array($data)) { extract($row); $building = $row[0]; $parking_lot = $row[1]; $Number_of_Empty_Spaces = $row[2]; $Distance = $row[3]; $time_l = $row[4]; $time_h=$row[5]; $location=$row[6]; echo tr\n td$building/td\n td$parking_lot/td\n td$Number_of_Empty_Spaces/td\n td$Distance/td\n td$time_h - $time_l mins/td\n
Re: [PHP] Retrieving Image Location in PHP from MySQL
On Sat, Mar 7, 2009 at 8:12 PM, Sashikanth Gurram sashi...@vt.edu wrote: I am just storing the location of the image(as a varchar type), not the image itself. For example for a particular image, the location is stored as C:\wamp\bin\apache\apache2.2.8\htdocs\Bldgs_lots\Burruss.jpg echo /table\n; $err=1; if ($img = file_get_contents($location, FILE_BINARY)) { if ($img = imagecreatefromstring($img)) $err = 0; } if ($err) { header('Content-Type: text/html'); echo 'htmlbodyp style=font-size:9pxError getting image.../p/body/html'; } else { header('Content-Type: image/jpeg'); imagejpeg($img); echo 'img src=mysqli.php?img=' . $location . ' border=1 height=150 width=200 alt=' . $build . ''; imagedestroy($img); } ? im really not sure why youre doing it this way, maybe you can elaborate..? the more-or-less straightforward way to do this, if you want the url in an image tag, is to expose access to these images through the webserver, so that you might have a url like (assume youre site is mysite.com), http://mysite.com/Bldgs_lots/Burruss.jpg and at that point, including it in a page becomes trivial. say you have the location, $location, from the db already, as above, then $url = 'http://mysite.com/' . $location; echo 'img src=' . $url . ' border=1 height=150 width=200 alt=' . $build . ''; also, if i were to guess why youre getting junk is b/c youre using the header() function to tell the browser youre sending out an image. i believe it will then try to treat w/e you send it as the binary of a jpeg. which img... is not. if you are trying to send just the image and not create a page of html, then theres no need for the img tag. iirc, all you need to do is call imagejpeg(). from the manual on imagejpeg(), The path to save the file to. If not set or *NULL*, the raw image stream will be outputted directly. so basically, just, else { header('Content-Type: image/jpeg'); imagejpeg($img); imagedestroy($img); } -nathan
Re: [PHP] Retrieving Image Location in PHP from MySQL
The thing is, I do not have a website or a place where I am storing my images. I am storing the images on my local PC in folder as mentioned in my earlier post. I have tried using only the else { header('Content-Type: image/jpeg'); imagejpeg($img); imagedestroy($img); } Which you have suggested. This is the piece of code which is returning all the binary character stuff. The code is definitely fetching the image. But it is not able to deliver to the browser in the form of an image. I am trying to read the image file as binary, evident from the FILE_BINARY command. So may be, that is causing the image to be displayed as binary. Is there any way we can convert the binary content to jpeg/jpg content again. This is my guess after having gone through the code again.\ Thanks, Sashi Nathan Nobbe wrote: On Sat, Mar 7, 2009 at 8:12 PM, Sashikanth Gurram sashi...@vt.edu wrote: I am just storing the location of the image(as a varchar type), not the image itself. For example for a particular image, the location is stored as C:\wamp\bin\apache\apache2.2.8\htdocs\Bldgs_lots\Burruss.jpg echo /table\n; $err=1; if ($img = file_get_contents($location, FILE_BINARY)) { if ($img = imagecreatefromstring($img)) $err = 0; } if ($err) { header('Content-Type: text/html'); echo 'htmlbodyp style=font-size:9pxError getting image.../p/body/html'; } else { header('Content-Type: image/jpeg'); imagejpeg($img); echo 'img src=mysqli.php?img=' . $location . ' border=1 height=150 width=200 alt=' . $build . ''; imagedestroy($img); } ? im really not sure why youre doing it this way, maybe you can elaborate..? the more-or-less straightforward way to do this, if you want the url in an image tag, is to expose access to these images through the webserver, so that you might have a url like (assume youre site is mysite.com), http://mysite.com/Bldgs_lots/Burruss.jpg and at that point, including it in a page becomes trivial. say you have the location, $location, from the db already, as above, then $url = 'http://mysite.com/' . $location; echo 'img src=' . $url . ' border=1 height=150 width=200 alt=' . $build . ''; also, if i were to guess why youre getting junk is b/c youre using the header() function to tell the browser youre sending out an image. i believe it will then try to treat w/e you send it as the binary of a jpeg. which img... is not. if you are trying to send just the image and not create a page of html, then theres no need for the img tag. iirc, all you need to do is call imagejpeg(). from the manual on imagejpeg(), The path to save the file to. If not set or *NULL*, the raw image stream will be outputted directly. so basically, just, else { header('Content-Type: image/jpeg'); imagejpeg($img); imagedestroy($img); } -nathan -- ~ ~ Sashikanth Gurram Graduate Research Assistant Department of Civil and Environmental Engineering Virginia Tech Blacksburg, VA 24060, USA -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Retrieving Image Location in PHP from MySQL
On Sat, Mar 7, 2009 at 9:36 PM, Sashikanth Gurram sashi...@vt.edu wrote: The thing is, I do not have a website or a place where I am storing my images. I am storing the images on my local PC in folder as mentioned in my earlier post. I have tried using only the else { header('Content-Type: image/jpeg'); imagejpeg($img); imagedestroy($img); } Which you have suggested. This is the piece of code which is returning all the binary character stuff. The code is definitely fetching the image. But it is not able to deliver to the browser in the form of an image. I am trying to read the image file as binary, evident from the FILE_BINARY command. So may be, that is causing the image to be displayed as binary. Is there any way we can convert the binary content to jpeg/jpg content again. This is my guess after having gone through the code again. i spent 2 minutes working on it and read this in the manual, the first param of imagejpeg(), An image resource, returned by one of the image creation functions, such as imagecreatetruecolor()http://us.php.net/manual/en/function.imagecreatetruecolor.php . so, then i tossed this together, http://nathan.moxune.com/echoImage.php ?php header('Content-Type: image/jpeg'); imagejpeg(imagecreatefromjpeg('./phpLogo.jpeg')); -nathan