469,326 Members | 1,541 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,326 developers. It's quick & easy.

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

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

Googd luck
Jan 26 '10 #7
kovik
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;
  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
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 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
zorgi
431 Expert 256MB
Hm, when things are this confusing I consult firebug. http://getfirebug.com/
Jan 28 '10 #13
kovik
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

Post your reply

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

Similar topics

2 posts views Thread by guoqi zheng | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.