Page 1 of 1

Retrieving images from a folder, with its path in mysql

Posted: Tue Jul 31, 2007 3:27 pm
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

Posted: Tue Jul 31, 2007 3:28 pm
by guitarlvr
can you post your code?

Posted: Tue Jul 31, 2007 3:34 pm
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 :)

Posted: Tue Jul 31, 2007 3:37 pm
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]

Posted: Tue Jul 31, 2007 3:46 pm
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 :!:

Posted: Tue Jul 31, 2007 3:54 pm
by s.dot

Code: Select all

while($array = mysql_fetch_array($result))
{
    echo '<img src="' . $array['imagepath'] . '" />';
}

Posted: Tue Jul 31, 2007 4:34 pm
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!!!

Posted: Tue Jul 31, 2007 5:47 pm
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..?

Posted: Wed Aug 01, 2007 1:12 am
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