-2

Please help me!

I have index.php where is the form

<form  id="form" method="post" action="action.php" enctype="multipart/form-data" > 
 <input type="file" id="file" name="file" />
  <input type="submit"  value="submit" class="btn btn-success"> 
</form>

what should I write in action.php to display the uploaded picture?

3 Answers3

0

just upload image file in any folder on your server in root directory by this:

move_uploaded_file()

and save image name in database field column

then you can get that name by from database and can display by this:

<?php 
// your mysql query

// goes here
?>

<img src="your_image_folder/<?php echo $your_fetch_row['image_column_name']; ?>" />
Dinesh
  • 4,066
  • 5
  • 21
  • 35
0

You can use move_uploaded_file. Try this..

if (file_exists("upload/" . $_FILES["file"]["name"])) {
    echo $_FILES["file"]["name"] . " already exists. ";
} else {
    move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]);
    echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}

Here upload is a folder name in root directory. For more here

MH2K9
  • 11,951
  • 7
  • 32
  • 49
0

Thank you to everyone. I found the answer!

if(!empty($_FILES['file']['tmp_name'])){ 

  $tmp = $_FILES['file']['tmp_name'];


  $name = $_FILES['file']['name'];
  $path = "images/".$name;
  move_uploaded_file($tmp, $path);
  echo "<img src='$path' alt='$name' />";
}