Retrieving images from a folder, with its path in mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bakary
Forum Newbie
Posts: 5
Joined: Tue Jul 31, 2007 3:18 pm
Location: Kenya

Retrieving images from a folder, with its path in mysql

Post by bakary »

Hi,

Please help me on how i should go about extracting images unto a web page using php.
This is the scenario

I have uploaded images to a folder and sent the path to the database.

I want, using the image path, to extract the images and display them in a page. I have been able to extract only the first image

Kindly help

Baks
Last edited by bakary on Tue Jul 31, 2007 3:28 pm, edited 1 time in total.
User avatar
guitarlvr
Forum Contributor
Posts: 245
Joined: Wed Mar 21, 2007 10:35 pm

Post by guitarlvr »

can you post your code?
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

You'll need to use the following PHP functions:

http://uk3.php.net/manual/en/function.opendir.php
http://uk3.php.net/manual/en/function.readdir.php

And the following loop:

http://uk3.php.net/manual/en/control-st ... .while.php

Good luck.


*** EDIT ***

Oops, sorry, didn't see you were using a database at first.

You'll need:

http://uk3.php.net/manual/en/function.mysql-query.php
http://uk3.php.net/manual/en/function.m ... -array.php


Again, good luck :)
bakary
Forum Newbie
Posts: 5
Joined: Tue Jul 31, 2007 3:18 pm
Location: Kenya

Post by bakary »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Here is the first page  (property.php)



[syntax="html"]<form enctype="multipart/form-data" action="propertyupload.php" method="post">

<table width="261" border="0">
  <tr>
    <td width="73"><span class="style11 style14 style13"><span class="style11 style14 style17"><span class="style11 style17 style14">Title</span></span></span></td>
    <td width="178"><input type="text" name="title" size="30" class="intheform"></td>
  </tr>
  <tr>
    <td><span class="style11 style14 style16"><span class="style11 style14 style13"><span class="style11 style14 style17"><span class="style11 style17 style14">Location</span></span></span></span></td>
    <td><input type="text" name="location" size="30" class="intheform"></td>
  </tr>
  <tr>
    <td><span class="style11 style14 style16"><span class="style11 style14 style13"><span class="style11 style14 style17"><span class="style11 style17 style14">Description</span></span></span></span></td>
    <td><input type="text" name="description" size="30" class="intheform"></td>
  </tr>
  <tr>
    <td><span class="style11 style14 style16"><span class="style11 style14 style13"><span class="style11 style14 style17"><span class="style11 style17 style14">Price</span></span></span></span></td>
    <td><input type="text" name="price" size="30" class="intheform"></td>
  </tr>
  <tr>
    <td><span class="style11 style14 style16"><span class="style11 style14 style13"><span class="style11 style14 style17"><span class="style11 style17 style14">PhoneNumber</span></span></span></span></td>
    <td><input type="text" name="phone" size="30" class="intheform"></td>
  </tr>
  <tr>
    <td><span class="style17"><strong>Email</strong></span></td>
    <td><input type="text" name="email" size="30" class="intheform"></td>
  </tr>
  <tr>
    <td><span class="style11 style14 style16"><span class="style11 style14 style13 style17"><span class="style11 style13 style17 style14">Image</span></span></span></td>
    <td>    <input type="hidden" name="MAX_FILE_SIZE" value="300000" />
    <!-- Name of input element determines name in $_FILES array -->    <input name="userfile" type="file" class="intheform" />
    <br />
    <input type="submit" class="intheform" /></td>
  </tr>
</table>
</body>
</html>


it submits to this:[/syntax]

Code: Select all

<?php 

include "../includes/config.php"; 

$uploaddir = '../uploads/'; 
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']); 

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { 
   echo "File is valid, and was successfully uploaded.\n"; 

$title=$_POST['title']; 
$location=$_POST['location']; 
$description=$_POST['description']; 
$price=$_POST['price']; 
$phone=$_POST['phone']; 
$email=$_POST['email']; 
$filenameurl= basename($_FILES['userfile']['name']);   //gets the base name

$sqlquery = "INSERT INTO property VALUES( idno,'$title','$location','$description',NOW(),'$price','$phone','$email','$filenameurl')";  //$filename now in database

$results = mysql_query($sqlquery) or die(mysql_error()); 

} else { 
   echo "Possible file upload attack!\n"; 
} 
echo "<br /><img src=\"$uploadfile\" />"; 
?>

After uploading around 5 images, i would like to display the images in a page.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
bakary
Forum Newbie
Posts: 5
Joined: Tue Jul 31, 2007 3:18 pm
Location: Kenya

Post by bakary »

Directory handle: Resource id #2 Files: . .. Quincy.jpg Thumbs.db lakers11.jpg nets1.jpg

This is the error it has posted. its reading the imageurls from the database but its not showing the images :!:
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Code: Select all

while($array = mysql_fetch_array($result))
{
    echo '<img src="' . $array['imagepath'] . '" />';
}
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
bakary
Forum Newbie
Posts: 5
Joined: Tue Jul 31, 2007 3:18 pm
Location: Kenya

Post by bakary »

it seems to be reading the number of images in the database, and displaying blank image placeholders? Anyone knows why?
Its been banging my head 4 like a whole week!!!
User avatar
nathanr
Forum Contributor
Posts: 200
Joined: Wed Jun 07, 2006 5:46 pm

Post by nathanr »

1: have you checked and verified the image has uploaded and is on the server?
2: have you checked the path "../uploads/imagename.jpg" or whatever is the correct link to the image..?
bakary
Forum Newbie
Posts: 5
Joined: Tue Jul 31, 2007 3:18 pm
Location: Kenya

Post by bakary »

If i select the specific row i want using the idno, it is displaying that particular image well. The problem is that i want to display all the images in the page using a loop or something
Post Reply