472,351 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,351 software developers and data experts.

How to insert image in php

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 69460
431 Expert 256MB
Expand|Select|Wrap|Line Numbers
  1. echo "<img src='$S' width='60' height='80' />";
Jan 25 '10 #2
@ 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
1,059 1GB
give the actual code, following the rule. your provided code is disturbing.
Jan 25 '10 #4
431 Expert 256MB
If you did this:

Expand|Select|Wrap|Line Numbers
  1. echo "<img src='$S' width='60' height='80' />";
and image is not displayed than your path $S must be wrong.
Jan 25 '10 #5
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
431 Expert 256MB
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.


Googd luck
Jan 26 '10 #7
1,044 Expert 1GB
<image> and <img> are not the same.
Jan 27 '10 #8
Expand|Select|Wrap|Line Numbers
  1. <h2> Here is your Quiz</h2>
  2. <?php
  3. $i=0;
  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 
  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>";      
  37. $i+=1;
  39. }
  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
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
1,044 Expert 1GB
Have you tried verifying that the image URL is correct by directly visiting it?
Jan 28 '10 #11
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
431 Expert 256MB
Hm, when things are this confusing I consult firebug. http://getfirebug.com/
Jan 28 '10 #13
1,044 Expert 1GB
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

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...
by: linus | last post by:
Anyone try insert image or binary files to MySQL using ASP.NET? Thanks a lot
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...
by: anuragpj | last post by:
how to insert image in a table in pgsql database.
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...
by: shekhar051 | last post by:
how to insert image as a back ground in header row in C#
by: yusufjammy | last post by:
How to insert image in mysql database via php and how to retrieve in php ?
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...
by: mohanty2050 | last post by:
How can I split a cell and insert image in a particular cell of a cross tab report?
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? ...
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

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.