thank you for ur help.
How will i now actually get the link to be stored in the database, and then later when i recall it, how will the server know its a link *how will the actual recall of the image be made*.
Thank you so much for your help so far!
php, mysql and images ... ARGH!
Moderator: General Moderators
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: php, mysql and images ... ARGH!
In order to insert the image into the database all you need to do is specify the name of the image file:
Now, in order to retrieve the image file and make it a link you would do:
It's pretty darn crude but it's one way of storing and retrieving an image.
Code: Select all
//GET THE IMAGE NAME FROM THE UPLOAD
$imgName=$_FILES['img']['name'];
//INSERT THE DATA - NOTE THE NEW VARIABLE $imgName
$sql = "INSERT INTO bushshirts (img,name,description) VALUES ('$imgName','$name','$description')";
Code: Select all
//SPECIFY WHERE THE IMAGES ARE STORED e.g. "http://www.site.com/images/uploads/"
$directory_to_uploads
//GET THE CORRECT RECORDS/PRODUCTS
$listProducts=mysql_query("SELECT * FROM bushshirts ORDER BY name");
//CHECK IF ANY PRODUCTS EXIST
if(mysql_num_rows($listProducts)>0)
{
//NOW OUTPUT THE RESULTS
while($productRow=mysql_fetch_array($listProducts))
{
echo $productRow['name'] . "<br />";
echo $productRow['description'] . "<br />";
echo '<a href="#"><img src=" ' . $directory_to_uploads . $productRow['img'] . ' " /></a>';
}
}
Re: php, mysql and images ... ARGH!
Well with the help of a friend, we managed to rather take the alternative route and put the images directly into the database. Although this is a longer route, we save the effort of likely over-writing some filenames and it loads fast enough ...
Our trouble came in to view the image later, only too find out you have to use a "image replacement file", or a php file with a script to actually view the image, with my little php knowledge, it was a ideal scenario where i had to use the little i know about the php and some common sense and BAM, there the images show and i learnt a great load with this exercise!
Thank you soo much for your help, i think i am falling in love with php, its definately easier than playing the guitar, but i also know i still have ALOT to learn, i just hate reading so darn! But knowledge is power, or atleast money in the bank
speak 2 u soon
Our trouble came in to view the image later, only too find out you have to use a "image replacement file", or a php file with a script to actually view the image, with my little php knowledge, it was a ideal scenario where i had to use the little i know about the php and some common sense and BAM, there the images show and i learnt a great load with this exercise!
Thank you soo much for your help, i think i am falling in love with php, its definately easier than playing the guitar, but i also know i still have ALOT to learn, i just hate reading so darn! But knowledge is power, or atleast money in the bank
speak 2 u soon
Re: php, mysql and images ... ARGH!
hi aceconceptsaceconcepts wrote:So you need to upload the image to a directory and also store it in the database and then retrieve it also?
Correct?
do you happen to have a complete script which is working?
as i cannot use the snippets of code you have posted thus far,
as it applies to nVee
thankyou for your time.
alto
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: php, mysql and images ... ARGH!
What exactly do you need?