Code: Select all
tags. Read the posting guidelines: http://forums.devnetwork.net/viewtopic.php?f=1&t=21171 for more info. Your post has been changed to reflect how we'd like to see it.[/color]
I have an input form for uploading to image to a table and a directory but when i run the script the image is not displayed on the web page below are both scripts used. I would appreciate any help i can get on this. Thank you.
first script:
[syntax=php]<html>
<head>
<title>Student Information Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
$uploadDir = 'C:/webserver/Apache2/htdocs/upload/';
$matric= UCFIRST($_POST['regnum']);
$title=UCFIRST($_POST['title']);
$name=UCFIRST($_POST['surname']);
$middle =UCFIRST($_POST['middle']);
$firstname=UCFIRST($_POST['firstname']);
$formername=UCFIRST($_POST['formersurname']);
$dob=$_POST['dob'];
if (isset($_POST['submit']) && $_FILES['userfile']['size'] > 0 && !empty($_POST['firstname']) && !empty($_POST['surname']) && !empty($_POST['dob']))
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$filePath = $uploadDir . $fileName;
$result = move_uploaded_file($tmpName, $filePath);
if (!$result)
{
echo "Error uploading file";
exit;
}
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
}
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$query = "INSERT INTO student_information".
"(regnum, title, surname, firstname, middle, former, birth, name, type, size, content)".
"VALUES ('$matric', '$title', '$name', '$firstname', '$middle', '$formername', '$dob', '$fileName', '$fileType', '$fileSize', '$content')";
mysql_query($query) or die("Error, query failed because ".Mysql_error());
$inf=mysql_query("SELECT id FROM student_information WHERE surname='$name' AND firstname='$firstname'") or die("Unable to retrieve id".mysql_error());
while ($ids=mysql_fetch_array($inf))
{
$id=$ids['id'];
echo $id;
}
echo "<h5><font color='663300'><i>Congrats</font> $title $name<font color='663300'>, Your form has been submitted. Print this page for future reference</font></i>.</h5>";
echo "Date of submission: ".date("l d, F, Y")."<br />";
echo "<table border='1' cellspacing='0' cellpadding='5' bgcolor='#D1D3F1'>
<tr>
<td colspan='2'><img src='sifpic.php?id=$id' /></td>
</tr>
<tr>
<td><b>Registration Number:</b></td>
<td> $matric<br</td>
</tr>
<tr>
<td><b>Name:</b></td>
<td> $title $name $firstname $middle</td>
</tr>
<tr>
<td><b>Date of Birth:</b></td>
<td> $dob</td>
</tr>
mysql_close();
}
?>
</body>
</html>
sifpic.php script
Code: Select all
<?php
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$result=mysql_query("SELECT content, type FROM student_information WHERE id=$id") or die("Can't perform query".mysql_error());
$row=mysql_fetch_assoc($result);
$type=$row['type'];
$image=$row['content'];
Header( "Content-type: $type");
Print $image;
?>pickle | When posting code, please enclose it in [ code ] or [ php ] tags. Read the posting guidelines: viewtopic.php?f=1&t=21171 for more info. Your post has been changed to reflect how we'd like to see it.