Hey guys,
I'm currently working on a little project and i've run into a little problem,
using dreamweaver I am creating a web page for a dental surgery and I
have created an admin log in which allows the admin staff to upload
images which are then meant to be displayed on the home page "index.php"
The images upload perfectly fine but I am having problems displaying the images
on the index.php page. I have tried using the img_src code but it does not dispay
images on the web page.
here is the code for the index.php page
<?php
session_start();
require('includes/config.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Welham Green Dental Surgery</title>
<title><?php echo SITETITLE;?></title>
<link href="<?php echo DIR;?>style/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
<div id="bannermain"><a href="<?php echo DIR;?>"><img src="images/banner2.png" alt="<?php echo SITETITLE;?>" title="<?php echo SITETITLE;?>" border="0" /></a></div><!-- close logo -->
<!-- NAV -->
<div id="navigation">
<ul class="menu">
<li><a href="<?php echo DIR;?>">Home</a></li>
<?php
//get the rest of the pages
$sql = mysql_query("SELECT * FROM pages WHERE isRoot='1' ORDER BY pageID");
while ($row = mysql_fetch_object($sql))
{
echo "<li><a href=\"".DIR."?p=$row->pageID\">$row->pageTitle</a></li>";
}
?>
</ul>
</div>
<img src= " images/uploads/"/>
<!-- END NAV -->
<div id="login">
<a href="http://localhost/welhamgreen/admin/login.php">Login</a>
</div>
<div id="content">
<div id="contentleft">
<!-- left NAV -->
<ul class="navleft">
<li><a href="<?php echo DIR;?>imageupload.php">Home</a></li>
<?php
//get the rest of the pages
$sql = mysql_query("SELECT * FROM pages WHERE isRoot='1' ORDER BY pageID");
while ($row = mysql_fetch_object($sql))
{
echo "<li><a href=\"".DIR."?p=$row->pageID\">$row->pageTitle</a></li>";
}
?>
</ul>
</div>
</div>
<!-- END NAV -->
<?php
//if no page clicked on load home page default to it of 1
if(!isset($_GET['p'])){
$q = mysql_query("SELECT * FROM pages WHERE pageID='1'");
} else { //load requested page based on the id
$id = $_GET['p']; //get the requested id
$id = mysql_real_escape_string($id); //make it safe for database use
$q = mysql_query("SELECT * FROM pages WHERE pageID='$id'");
}
//get page data from database and create an object
$r = mysql_fetch_object($q);
//print the pages content
echo "<h1>$r->pageTitle</h2>";
echo $r->pageCont;
?>
</div>
<!-- close content div -->
<div id="footer">
<div class="copy">© <?php echo SITETITLE.' '. date('Y');?> </div>
</div><!-- close footer -->
</div><!-- close wrapper -->
</body>
</html>
and here is the code for the upload script
<?php
$uploaddir = "uploads";
$allowed_ext = "jpg, JPG, png, gif";
$max_size = "5000000";
$max_height = "4000";
$max_width = "4000";
$extension = pathinfo($_FILES['file']['name']);
$extension = $extension[extension];
$allowed_paths = explode (", ", $allowed_ext);
for ($i = 0; $i < count ($allowed_paths); $i++) {
if ($allowed_paths[$i] == "$extension") {
$ok = "1";
}
}
if ($ok == "1") {
if ($_FILES['file']['size'] > $max_size)
{
print "File is too big!! <a href='index.php'>Please try again!</a>";
exit;
}
if ($max_width && $max_height) {
list ($width, $height, $type, $w) =
getimagesize($_FILES['file']['tmp_name']);
if($width > $max_width || $height > $max_height)
{
print "File height and/or width are too bug!";
exit;
}
}
if(is_uploaded_file($_FILES['file']['tmp_name']))
{
move_uploaded_file($_FILES['file']['tmp_name'], '../index.php' .'/'.$_FILES['file']['name']);
}
print "Your file has been uploaded successfully! Yay!";
echo "<a href='../index.php'>Click here to view your image.</a>";
} else {
print "Incorrect file extension!";
}
?>
I would really appreciate some help.
Regarding PHP image upload and display script
Moderator: General Moderators