Sunday 20 April 2008

Make image upload unique to all visitors

The Problem: we will be having a number of users - at present all their photos will be going into one folder. So if they have the same filenames the latest picture will over write the rest and show on everyone elses listings.

The Solution.

when landlords upload their images if we then upload these images into a folder that is unique ( taken from a unique number on their database )


--Next stage >>

So basically we'll need to add to the admin section in landlords where they add and edit images. In my project this is landlords/edit.php & landlords/add.php

And then we'll need change all pages that display properties to read from the correct folder.
In my project this is - index.php & members/details.php & search/index.php



######################################################################

landlords/add.php


I have a value in this page named $abpath -
this value is set in includes/config.php and is for the images folder. So what I need to do is change $abpath to includes the unique folder number. Create the folder. Chmod the folder ( set the write settings). And then send the image to that folder.

So back to that unique folder. In my mysql table 'listings' I have a colomn '$rid' which is unique to all properties. Firstly I need to get that number, it gets created in landlords/add.php on the insert on line 131

INSERT INTO listings (llid, rtype, addone, addtwo, city, state, postcode1, postcode2, pets,websiteURL , descrip, bed, bath, garage, yard, utilities, rent, deposit, listdate, starRating, img1, img2, img3, img4, img5, img6, img7, img8) VALUES ('$llid', '$proptype', '$add', '$addtwo', '$city', '$state', '$postcode1', '$postcode2', '$pets','$websiteURL' , '$description', '$bedroom', '$bathroom', '$garage', '$yard', '$utilities', '$rent', '$deposit', '$tdate', '$starRating', '$imgone', '$imgtwo', '$imgthree', '$imgfour', '$imgfive', '$imgsix', '$imgseven', '$imgeight'


Underneath I have used

$listings = mysql_query("SELECT * FROM listings WHERE llid='$llid' AND img1='$imgone' AND postcode2='$postcode2' ");
$listingRow = mysql_fetch_array($listings);

$rid = $listingRow['rid'];

this is a tight as I think I need to make the search on this detail. However if we think landlords will be using more than one property with the same main image and postcode then we may have a problem.
Otherwise we should be getting our unique number stored in $rid back to use to make a folder.

THEN UNDERNEATH ENTER

$abpath = $abpath .$rid.'/';

// this sets the new path where we want our folder



THEN UNDERNEATH ENTER

if ( !is_dir($abpath)){
mkdir($abpath, 0700);
}


// if this directory doesn't exist creat it and set the security level


THATS ALL FOR THIS PAGE.




######################################################################



landlords/edit.php

this page is much easier as $rid is already in use so all we need to add is on line 162 ENTER

$abpath = $abpath .$rid.'/';


##############################################################


ON ALL DISPLAY PAGES


search for all images -

code for images will appear as such

"../images/"row['img3']."\"


this needs to be changed to

"../images/".$row['rid']."/".$row['img3']."\"




AND THATS IT --

No comments: