473,508 Members | 2,265 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to insert image in php

6 New Member
Hii all
It might be a silly doubt but I am puzzled a lot by it.
Basically my application need to display uploaded file from user.
The name of image file is variable. Lets say the path to uploaded file is stored in
Following four are various combination of $s
Expand|Select|Wrap|Line Numbers
  1. $S. Now when i used following commands
  2. $s="http://localhost/myfolder/imagefolder/image.jpeg"       //with quotations
  3. $s="c://xampp/htdocs/myfolder/imagefolder/image.jpeg"   
  4. $s=http://localhost/myfolder/imagefolder/image.jpeg         //without quotations
  5. $s=c://xampp/htdocs/myfolder/imagefolder/image.jpeg
Following four commands are various syntax used to display image corresponding to each of the above $s
Expand|Select|Wrap|Line Numbers
  1. echo "img src="$S" width="60" height="80" ";
  2. echo "img src='$S' width='60' height='80' ";
  3. echo "img src=$S width='60' height='80' ";
  4. echo "img src=".$S. "width='60'". "height='80' ";
Jan 25 '10 #1
13 69667
zorgi
431 Recognized Expert Contributor
Expand|Select|Wrap|Line Numbers
  1. echo "<img src='$S' width='60' height='80' />";
  2.  
Jan 25 '10 #2
vikamjain
6 New Member
@ Zorgi Sorry, In my question i forgot to put <> but in actual i have tried this command
echo "<image src='$S' width='60' height='80' />";
but it did not work for me
Jan 25 '10 #3
johny10151981
1,059 Top Contributor
give the actual code, following the rule. your provided code is disturbing.
Jan 25 '10 #4
zorgi
431 Recognized Expert Contributor
If you did this:

Expand|Select|Wrap|Line Numbers
  1. echo "<img src='$S' width='60' height='80' />";
  2.  
and image is not displayed than your path $S must be wrong.
Jan 25 '10 #5
vikamjain
6 New Member
helllo jorgi I used follwing four kind of pathnames in $s
Expand|Select|Wrap|Line Numbers
  1. $s="http://localhost/myfolder/imagefolder/image.jpeg" //with quotations
  2. $s="c://xampp/htdocs/myfolder/imagefolder/image.jpeg"
  3. $s=http://localhost/myfolder/imagefolder/image.jpeg //without quotations
  4. $s=c://xampp/htdocs/myfolder/imagefolder/image.jpeg
but none of them worked
Jan 26 '10 #6
zorgi
431 Recognized Expert Contributor
Well its difficult for me to tell where are your image files but it looks to me as if you should do some reading on absolute and relative paths. There is loads of articles on internet on the subject. Just google for it. Here is one i found. I have't read it but I hope it helps.

http://support.internetconnection.ne...le_Paths.shtml

Googd luck
Jan 26 '10 #7
kovik
1,044 Recognized Expert Top Contributor
<image> and <img> are not the same.
Jan 27 '10 #8
vikamjain
6 New Member
Expand|Select|Wrap|Line Numbers
  1. <h2> Here is your Quiz</h2>
  2. <?php
  3. $i=0;
  4.  
  5. echo "<table border=\"1\" align=\"top\">";
  6. echo "<tr><th>Question no</th>";
  7. echo "<th>Question </th>";
  8. echo "<th>Hint</th>";
  9. echo "<th>Answer</th>";
  10. echo "<th>Picture</th></tr>";
  11. echo "<tr><td>";
  12. while($i<$num)
  13. {
  14.   $qnn= mysql_result($result,$i, "Question_no");
  15.   $qn= mysql_result($result,$i, "Question");
  16.   $hint=mysql_result($result,$i, "Hint");
  17.   $ans=mysql_result($result,$i, "Answer");
  18.   $pic=mysql_result($result,$i, "Picture");
  19.   $pic1="http://localhost/test2/uploaded_files/1264644980-11_17250697.jpg";
  20.   echo $pic; 
  21.   // $pic on echo command gives http://localhost/test2/uploaded_file...1_17250697.jpg
  22.    echo $pic1;
  23.   // $pic1 on echo command gives http://localhost/test2/uploaded_file...1_17250697.jpg 
  24.  
  25.         echo "<tr><td>";
  26.     echo $qnn;
  27.     echo "</td><td>";
  28.     echo $qn;
  29.     echo "</td><td>";
  30.         echo $hint;
  31.         echo "</td><td>";
  32.         echo $ans;
  33.         echo "</td><td>";
  34.         echo "<img src='$pic1' />";
  35.         echo "</td></tr>";      
  36.  
  37. $i+=1;
  38.  
  39. }
  40.  
  41. ?>

//Here Value of Picture is passed using following command in some other file
// $s='http://' . $_SERVER['HTTP_HOST'] . $directory_self.'/uploaded_files/'.$now.$_FILES[$fieldname]['name'];
Jan 28 '10 #9
vikamjain
6 New Member
here all the connection to database are done in some other file. This file was included in that file so connection won't be a problem. $pic1 is showing the picture while $pic is not showing the picture when used in the command
echo "<img src='$pic or $pic1' />";
Jan 28 '10 #10
kovik
1,044 Recognized Expert Top Contributor
Have you tried verifying that the image URL is correct by directly visiting it?
Jan 28 '10 #11
vikamjain
6 New Member
As I said before I have given the actual url value in $pic1. which is working fine and when I used $pic which has the same value as $ pic1(which is evident from this fact that both are giving same thing when echo command is used)
Jan 28 '10 #12
zorgi
431 Recognized Expert Contributor
Hm, when things are this confusing I consult firebug. http://getfirebug.com/
Jan 28 '10 #13
kovik
1,044 Recognized Expert Top Contributor
You said that neither is working. You'll need to be much clearer if you want to get this solved.

If one works and the other doesn't, then they are NOT equal, regardless of what you think. Double-check them by copying the URL that they echo from the HTML in the <img> tag. Also, compare the two values using the "===" operator.
Jan 28 '10 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1476
by: Abhishek Bagga | last post by:
I want to insert Image in the column headers of the Listview control I have been trying this but was unable to achieve it. Is it possible? if yes kindly guide me how to achieve this. -- -...
0
1451
by: linus | last post by:
Anyone try insert image or binary files to MySQL using ASP.NET? Thanks a lot
2
5498
by: guoqi zheng | last post by:
dear sir, I am using itextShap for pdf generation. I know I can insert image into it, I can add header to it as well. However, I can not add an image as a header. Does any one has experience...
1
12865
by: anuragpj | last post by:
how to insert image in a table in pgsql database.
0
1684
by: gazanfar | last post by:
Yes thanks Question is that ---I want to insert image/or image path in my SQlServer 2000 through Visual basic application.like after scan of any photo i want insert in database on whoever's no...
2
1371
by: shekhar051 | last post by:
how to insert image as a back ground in header row in C#
2
4162
by: yusufjammy | last post by:
How to insert image in mysql database via php and how to retrieve in php ?
2
11344
by: lwannwayoo | last post by:
Hi Everybody! I have a database in Microsoft Access 2003 and I want to insert image in my Table Field. How can I don it??. I use OLE type but when i insert image to that field only the word...
2
1811
by: mohanty2050 | last post by:
How can I split a cell and insert image in a particular cell of a cross tab report?
3
3100
by: Napsterr | last post by:
I have a RichTextEditor control. I want to insert image whereever the cursor is. Onclicking Insert link i want to insert Image. Is it possible? I have this design in .aspx page. After...
0
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7132
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7401
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7063
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5640
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.