putting images from mysql to folder

Codes here !

Moderators: macek, egami, gesf

mightyhokie
New php-forum User
New php-forum User
Posts: 6
Joined: Fri Jun 01, 2012 2:51 pm

putting images from mysql to folder

Postby mightyhokie » Fri Jun 01, 2012 3:05 pm

I have created a real estate site for a client. I created a form where they can upload data to a mySQL database (stuff like MLS#, address, city, etc). They also want several images per property, so in the DB I set up five fields (BLOB) and figured out how to input that data in the same form. I know because i've read a billion places that putting and using images into a database is a bad bad idea. I get that. I know the best route is to 'put your images into a folder and use php to reference the path'. Great. I would if I could but the user is going to be putting the images into their site using a form. The only way I knew how to do that was put it in the mySQL as a blob. The user isn't savy enough to go onto the host and place the images into a folder.
So what I need, what it seems everyone says to do at this point, is to use a 'simple script' that takes the blob data/images from the DB and have that script place it in a folder on the site and replaces the data in the mysql with a path name. But while everyone tells me this no one tells me how, nor can i find anything about it on the web.

Please help.

Below is the whole page (I use DreamWeaver for this stuff because I'm new to php/mysql). I'm open to any suggestions.

<?php require_once('Connections/dottieann.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

$maxRows_rsMultiListings = 9;
$pageNum_rsMultiListings = 0;
if (isset($_GET['pageNum_rsMultiListings'])) {
$pageNum_rsMultiListings = $_GET['pageNum_rsMultiListings'];
}
$startRow_rsMultiListings = $pageNum_rsMultiListings * $maxRows_rsMultiListings;

mysql_select_db($database_dottieann, $dottieann);
$query_rsMultiListings = "SELECT listingsID, title, `lastModified`, address, city, `state`, zip, price, mlsID, img1 FROM listings ORDER BY `lastModified` ASC";
$query_limit_rsMultiListings = sprintf("%s LIMIT %d, %d", $query_rsMultiListings, $startRow_rsMultiListings, $maxRows_rsMultiListings);
$rsMultiListings = mysql_query($query_limit_rsMultiListings, $dottieann) or die(mysql_error());
$row_rsMultiListings = mysql_fetch_assoc($rsMultiListings);

if (isset($_GET['totalRows_rsMultiListings'])) {
$totalRows_rsMultiListings = $_GET['totalRows_rsMultiListings'];
} else {
$all_rsMultiListings = mysql_query($query_rsMultiListings);
$totalRows_rsMultiListings = mysql_num_rows($all_rsMultiListings);
}
$totalPages_rsMultiListings = ceil($totalRows_rsMultiListings/$maxRows_rsMultiListings)-1;



?>

<!DOCTYPE>
<html>
<head>


<?php
include "_include/phpCode.php";
?>


<?php
include "_include/styles.php";
?>

<title>Dottie Dooley and V. Ann Rozier Realtors</title>
</head>

<body>
<div id="wrapper">

<?php
include "_include/header.php";
?>

<div id="contentContainer">
<div class="contentContainerHeader"> Our Listings</div>

<div class="listingsContainer">

<?php do { ?>
<div class="singleListingsContainer">
<div class="imgBox"><?php echo $row_rsMultiListings['img1']; ?></div>
<div class="thumbMLS">MLS: <?php echo $row_rsMultiListings['mlsID']; ?></div>
<div class="address">
<?php echo $row_rsMultiListings['address']; ?> <br />
<?php echo $row_rsMultiListings['city']; ?>, <?php echo $row_rsMultiListings['state']; ?> <?php echo $row_rsMultiListings['zip']; ?> </div>
<div class="price">$<?php echo $row_rsMultiListings['price']; ?></div>
<div class="button"><a href="linkToBig">details</a></div>
</div>
<?php } while ($row_rsMultiListings = mysql_fetch_assoc($rsMultiListings)); ?><!-- end singleListingsContainer-->

<div class="nextPrevBtn"> Our Listings</div>
<!-- next and previous line-->
</div><!-- end listingsContainer-->

</div> <!--end contentContainer-->


<?php
include "_include/footer.php";
?>

</div> <!--end wrapper-->
</body>
</html>
<?php
mysql_free_result($rsMultiListings);
?>

SystemX
New php-forum User
New php-forum User
Posts: 8
Joined: Sat Jun 02, 2012 3:15 am

Re: putting images from mysql to folder

Postby SystemX » Sat Jun 02, 2012 7:28 am

Hi, im not too sure what exactly you meen but why not add an upload images button and allow the users/clients to upload photos/images with that and the php script will store the images to a folder that you set and then use mysql to store the url/path of the image. Then you can retrieve that url/path later to display the images.

Also the images can be on any site and can be displayed on your site with just the url to that image.

Regards

mightyhokie
New php-forum User
New php-forum User
Posts: 6
Joined: Fri Jun 01, 2012 2:51 pm

Re: putting images from mysql to folder

Postby mightyhokie » Sat Jun 02, 2012 11:54 am

Basically its this:
I have two 70 year old women who are real estate agents and tech unsavy. They need to be able to add/edit/and delete listings (I've made the database for this as well as the add/edit/delete pages).
They add/edit all the info (title, address, mls#, etc) then have need to select 5 images. Those images will be displayed on the 'full listings' page and a 'single listing' page. So they have need to upload images from their computer to the host, and the pages need to have access to them and display them.
I do not know how to create an upload in php that sends images to a folder in the root directory then populates the database with that path. That would be the number 1 choice for this site, but I don't know how to do it.

If that is what you are telling me I should do can you also tell me how to do it? Pretty please?

Thanks.
MightyHokie

SystemX
New php-forum User
New php-forum User
Posts: 8
Joined: Sat Jun 02, 2012 3:15 am

Re: putting images from mysql to folder

Postby SystemX » Sat Jun 02, 2012 2:06 pm

Yes is the best way to do it that i can think of.

For the upload php script if you google it there are many, you can also add it to the form to keep everything in 1 place.

Then once the upload function is working, add an array to store the path of the uploaded image and then write that array to the database(it will write the path of the image) or you could use varibles instead of arrays.

Its not hard to find the scripts on google, the hardest part for you maybe adding the php together to work as 1.

Uploading scripts are fairly small too, just make sure that it will only allow to upload images and nothing else.

If i had the time i would have made this for you, but time is something that i dont have much of atm.

Regards

Novica89
New php-forum User
New php-forum User
Posts: 7
Joined: Fri May 18, 2012 5:34 am

Re: putting images from mysql to folder

Postby Novica89 » Sun Jun 03, 2012 2:23 am

Take a look at series of PHP tutorial videos at phpacademy YouTube channel.
Start with this video and go further,there are more videos about accepting uploaded files and putting them in directories...
http://www.youtube.com/watch?v=PYSW-Xej ... plpp_video

mightyhokie
New php-forum User
New php-forum User
Posts: 6
Joined: Fri Jun 01, 2012 2:51 pm

Re: putting images from mysql to folder

Postby mightyhokie » Sun Jun 10, 2012 5:45 pm

I was out of town last week and didn't get to respond to yalls posts. Thank you very much. This is a great start. Heck, I didn't even really know what key words I needed to use in a search. ha!

I'll respond back once I have it done or if I really get into trouble somehow. I will def back it all up before I start adding code. Dreamweaver is a blessing and a curse. I used it for years and years without ever knowing any html or css. Later I got my act together and learned all that stuff but I'm up against a hard deadline and it does make it quicker.

Anyway, thanks to all you guys.
MightyHokie (aka Van)


Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 0 guests