14 Replies - 0 Views - Last Post: 19 minutes ago Rate Topic: -----

#1 mwascoder  Icon User is online

  • New D.I.C Head

Reputation: 0
  • Posts: 5
  • Joined: Today, 10:54 AM

displaying images

Posted Today, 11:12 AM

hi,i have the code below.i want to upload images to a file,store the path into mysql database then display the images uploaded using the path.
the upload part and the path parts are ok,,but displaying part wont work.
where am i going wrong
 <?php
include'config.php';
$name=$_FILES['img']['name'];
$size=$_FILES['img']['size'];
$mimetype=$_FILES['img']['type'];
$temp=$_FILES['img']['tmp_name'];

$base="place/";//where the file will be stored
$base=$base . basename($_FILES['img']['name']);
if(move_uploaded_file($_FILES['img']['tmp_name'],$base)){
echo"The file " . basename($_FILES['img']['name']) . " has been uploaded";
$sql=("insert  into images (img,temp,mimetype) values('$name','$temp','$mimetype')");
$sql1=mysql_query($sql)  ;}else{
echo" stuff";
}

$sql2="select * from images";
$sql3=mysql_query($sql2);

while($row=mysql_fetch_array($sql3)){
echo "<img src='" . $row['img'] . "' height='200' width='200'/>";
}
?> 


Is This A Good Question/Topic? 0
  • +

Replies To: displaying images

#2 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3484
  • View blog
  • Posts: 10,041
  • Joined: 08-June 10

Re: displaying images

Posted Today, 11:19 AM

if the displaying doesn’t work, chances are that the image’s location is wrong. you’re saving it relatively to the uploading script, which does no necessarily be the web root.
Was This Post Helpful? 1
  • +
  • -

#3 mwascoder  Icon User is online

  • New D.I.C Head

Reputation: 0
  • Posts: 5
  • Joined: Today, 10:54 AM

Re: displaying images

Posted Today, 11:24 AM

hey.am php newbie assist please

This post has been edited by Dormilich: Today, 11:37 AM

Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3198
  • View blog
  • Posts: 10,731
  • Joined: 12-December 12

Re: displaying images

Posted Today, 11:29 AM

As a first step you could open the database-table in phpMyAdmin or similar and check what is held in the 'img' field.

Also look at the img-tags in the html source.

This post has been edited by andrewsw: Today, 11:30 AM

Was This Post Helpful? 1
  • +
  • -

#5 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 557
  • View blog
  • Posts: 2,499
  • Joined: 03-December 12

Re: displaying images

Posted Today, 11:29 AM

You need to assist yourself as well. As pointed out, your file path. What is it when you try to display it? If you are pointing to a directory that doesn't exist, you found your problem and how to correct it. If, it points to the correct file and location, there is a different issue.
Was This Post Helpful? 0
  • +
  • -

#6 mwascoder  Icon User is online

  • New D.I.C Head

Reputation: 0
  • Posts: 5
  • Joined: Today, 10:54 AM

Re: displaying images

Posted Today, 11:38 AM

View Postandrewsw, on 26 July 2014 - 11:29 AM, said:

As a first step you could open the database-table in phpMyAdmin or similar and check what is held in the 'img' field.

Also look at the img-tags in the html source.

the 'img' field holds the name of the image like comf.png
img-tags in the html source has ' <img src='comf.jpg' width='175' height='200' /> '

This post has been edited by Atli: Today, 11:41 AM

Was This Post Helpful? 0
  • +
  • -

#7 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 557
  • View blog
  • Posts: 2,499
  • Joined: 03-December 12

Re: displaying images

Posted Today, 11:41 AM

So, are your images in their own directory or are they stored in the same directory that is calling them?
Was This Post Helpful? 0
  • +
  • -

#8 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3198
  • View blog
  • Posts: 10,731
  • Joined: 12-December 12

Re: displaying images

Posted Today, 11:44 AM

So one's a .png and ones a .jpg..?

The images should be stored in a folder named 'place' but the stored image-name doesn't include this location.

This post has been edited by andrewsw: Today, 11:45 AM

Was This Post Helpful? 0
  • +
  • -

#9 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3484
  • View blog
  • Posts: 10,041
  • Joined: 08-June 10

Re: displaying images

Posted Today, 11:47 AM

View Postmwascoder, on 26 July 2014 - 08:38 PM, said:

the 'img' field holds the name of the image like comf.png
img-tags in the html source has ' <img src='comf.jpg' width='175' height='200' /> '

but you image is in place/ so it should be at least place/comf.png
Was This Post Helpful? 1
  • +
  • -

#10 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5180
  • View blog
  • Posts: 26,875
  • Joined: 10-May 07

Re: displaying images

Posted Today, 11:50 AM

Quote

echo "<img src='" . $row['img'] . "' height='200' width='200'/>";

Rather than run the code on the above line, echo it out, or look at it with your browser (the html code) & verify that the location of the image is correct.

Is there somewhere where we can view this html code (output) & try our best to look at it?
Was This Post Helpful? 0
  • +
  • -

#11 mwascoder  Icon User is online

  • New D.I.C Head

Reputation: 0
  • Posts: 5
  • Joined: Today, 10:54 AM

Re: displaying images

Posted Today, 11:52 AM

View Postandrewsw, on 26 July 2014 - 11:44 AM, said:

So one's a .png and ones a .jpg..?

The images should be stored in a folder named 'place' but the stored image-name doesn't include this location.

nah all have a .jpg extension
am actually having like broken images..[i mean those stuff that will always appear on a page if the image doesn't load completely]
Was This Post Helpful? 0
  • +
  • -

#12 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5180
  • View blog
  • Posts: 26,875
  • Joined: 10-May 07

Re: displaying images

Posted Today, 11:53 AM

View Postmwascoder, on 26 July 2014 - 02:38 PM, said:

img-tags in the html source has ' <img src='comf.jpg' width='175' height='200' /> '

This should contain the full path. something like the following is more correct :

<img src='http://site.com/path/comf.jpg' width='175' height='200' /> 

Was This Post Helpful? 1
  • +
  • -

#13 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3198
  • View blog
  • Posts: 10,731
  • Joined: 12-December 12

Re: displaying images

Posted 35 minutes ago

@no2pencil it doesn't require the full path, just 'place/comf.jpg' if place is at the same location as the current page.
Was This Post Helpful? 0
  • +
  • -

#14 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5180
  • View blog
  • Posts: 26,875
  • Joined: 10-May 07

Re: displaying images

Posted 31 minutes ago

Until the OP understands relative root, I disagree :)

That is to say, obviously the technology doesn't require it, but after working with too much information, I feel the OP will get a better understanding for what the webserver is doing when it receives, stores, & serves the file by using the full path including domain. Yes, technically just using the path relative to the file will work, but that was the first response & the OP didn't understand.

My thought process was to over-explain it though example. When the OP learns, the OP can chose to continue with the fqdn, or just relative to web root.
Was This Post Helpful? 1
  • +
  • -

#15 mwascoder  Icon User is online

  • New D.I.C Head

Reputation: 0
  • Posts: 5
  • Joined: Today, 10:54 AM

Re: displaying images

Posted 19 minutes ago

hoooorey got it...big thanks to you all
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1