Hello, Can anyone help me with my code, I am trying to retrieve a picture that I saved in a file on my server, the name was saved in MySQL and I want to retrieve it after it is uploaded and post it in a comment box. Here is the code: The problem I am having is te picture uploads perfect, but then it gives me a filename not found error when it is suppose to display the picture. Please help!!!!!!!
<?php
include('config3.php');
if($_POST)
{
// $_FILES["file"]["error"] is HTTP File Upload variables $_FILES["file"] "file" is the name of input field you have in form tag.
if ($_FILES["file"]["error"] > 0)
{
// if there is error in file uploading
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
// check if file already exit in "images" folder.
if (file_exists("uploads/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
if(move_uploaded_file($_FILES["file"]["tmp_name"],"uploads/" . $_FILES["file"]["name"]))
{
// If file has uploaded successfully, store its name in data base
$query_image = "INSERT into acc_images (image, status, acc_id) values ('".$_FILES['file']['name']."', 'display','')";
if(mysql_query($query_image))
{
}
}
}
}
$query_image = "SELECT * FROM acc_images acc_ id='$id'";
$result = mysql_query($query_image);
if(mysql_num_rows($result) > 0)
{
while($row = mysql_fetch_array($result))
{
echo '<img alt="" src="uploads/'.$row["image"].'">';
}
}
echo 'File name not found in database';
}
?>
<html>
<body>
<form action="upload.php" method="post"enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>