Photos in php
Posted: Fri Aug 11, 2006 11:37 am
Hello all!!
I have a slight little problem with a page I'm making.. The LAST thing I have yet to do is be able to upload an image onto the server, save the path into a MySQL Database, then take the path out of the database and display the picture on the page. Why this normally wouldn't be hard to do, the pages are search engine friendly (http://www.sitepoint.com/article/search ... endly-urls). The problem I am having is that the path to the image IS stored in the database, but when I use this piece of code to pull it out:
and the code to upload it:
(yes I know that the above block of code is horribly shown, but when I pasted it, it was VERY messed up)
But anyways.. the picture isn't displayed. If you need an example, go to one of the pages that I made and see for yourself:
http://www.nearnorth1.com/Business/Businesses2.php/8
I looked at the information for the bottom image (the top, smaller one by the number is a different method I tried to get the image), it says the adress is that of the script. I don't remember if it should say that.. So if anyone can help me, I'd really appreciate it!!
Mike
(note: The reason it says Creative on the page is because I used the first word that came to my head to fill in the form)
I have a slight little problem with a page I'm making.. The LAST thing I have yet to do is be able to upload an image onto the server, save the path into a MySQL Database, then take the path out of the database and display the picture on the page. Why this normally wouldn't be hard to do, the pages are search engine friendly (http://www.sitepoint.com/article/search ... endly-urls). The problem I am having is that the path to the image IS stored in the database, but when I use this piece of code to pull it out:
Code: Select all
include_once("db.inc");
$link = mysql_connect($host,$user,$pass,true)
mysql_select_db($db);
$query = "SELECT * FROM SiteInfo WHERE InfoID = $pagetoload";
$result = mysql_query($query);
$Site = mysql_fetch_object($result,$link);
echo($Site->photopath);
echo"<img src=\"$Site->photopath\" alt=\"Featured Picture\" title=\"Featured Picture\"width=\"250\" height=\"165\" border=\"0\" style= \"border:\"3px\"\"/></a> <br />";Code: Select all
#####################
# PHOTO UPLOAD
####
print_r($_POST); //Testing only
unset($imagename);
if(!isset($_FILES) && isset($HTTP_POST_FILES))
$_FILES = $HTTP_POST_FILES;
if(!isset($_FILES['image_file']))
$error["image_file"] = "An image was not found.";
$imagename = basename($_FILES['image_file']['name']);
echo $imagename;
if(empty($imagename))
$error["imagename"] = "The name of the image was not found.";
if(empty($error))
{
$newimage = $imagename;
echo $newimage;
$result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage);
if(empty($result))
$error["result"] = "There was an error moving the uploaded file.";
}But anyways.. the picture isn't displayed. If you need an example, go to one of the pages that I made and see for yourself:
http://www.nearnorth1.com/Business/Businesses2.php/8
I looked at the information for the bottom image (the top, smaller one by the number is a different method I tried to get the image), it says the adress is that of the script. I don't remember if it should say that.. So if anyone can help me, I'd really appreciate it!!
Mike
(note: The reason it says Creative on the page is because I used the first word that came to my head to fill in the form)