Retrieving images from a folder, with its path in mysql
Moderator: General Moderators
Retrieving images from a folder, with its path in mysql
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
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.
-
impulse()
- Forum Regular
- Posts: 748
- Joined: Wed Aug 09, 2006 8:36 am
- Location: Staffordshire, UK
- Contact:
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
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
feyd | Please use
it submits to this:[/syntax]
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]
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]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.