If someone could help I'd be very greatful.![]()
I have a mysql database with a column called "photo"
I have managed to write the php to upload an image into a flat file in my root directory and from here place to url of the image into the "photo" column of the db. My problem now is retrieving the image and displaying it.
My code is as follows; (This is from Kevins book by the way)
Image upload file:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form action="fileupload.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
<p>Select file to upload: <input type="file" name="uploadedfile" /></p>
<p><input type="submit" name="submit" value="Upload" />
</p>
</form>
</body>
</html>
This refers to a php file:
Everything goes well until I try to retrieve the file location from the database. Nothing happens just a blank space. I've spent about 8 hours trying to solve this so it's not as if I haven't tried!PHP Code:<!-- fileupload.php -->
<?php
$username = "johneeeee";
if ($uploadedfile_type == "image/pjpeg"
or $uploadedfile_type == "image/gif") {
//Handle the file...
}else{
echo ("<p>Please submit a JPEG or GIF image " .
"file.</p>\n");
exit();
}
// Pick a file extension
if ( "image/pjpeg" == $uploadedfile_type ) $extension = ".jpg";
else $extension = ".gif";
// The complete path/filename
$filename = "C:/uploads/" . time() . $REMOTE_HOST . $extension;
// Copy the file (if it is deemed safe)
if (is_uploaded_file($uploadedfile) &&
copy($uploadedfile, $filename)) {
echo("<p>File stored successfully as $filename.</p>");
}else{
echo ("<p>Could not save file as $filename!</p>");
exit();
}
$dbcnx = mysql_connect("localhost", "root", "*****");
if (!dbcnx) {
echo ("<p>Unable to connect to database server at this time!</p>");
exit();
}
mysql_select_db("dbName",$dbcnx);
if (! @mysql_select_db("dbName") ) {
echo ("Unable to locate the dbName database at this time.</p>");
exit();
}
$sql = "update name_address
set photo='$filename'
WHERE username = '$username' ";
if (@mysql_query($sql)) {
echo("<p>$filename successfully placed in database.</p>");
}else{
echo("<p>Error adding $filename to database!</p>");
}
"SELECT photo FROM name_address WHERE username = '$username'";
echo "<img src=$photo>";
?>![]()
Well that's it, if you can help please do.




Bookmarks