Q: PHP/MySQLI - Image Upload & Show Image Stackoverflow
Im currently developing a page, where i need to make a news system. 
The news system is all working fine, but there need to be a function to upload images (when creating the news) and showing them.
So it should be like, upload picture (Max size and so on) and it will upload to a folder on my server, and create the path in the mysql database.
Best Regards, Kristian

A: form  
   <form action="accept-file.php" method="post" enctype="multipart/form-data">
        Your Photo: <input type="file" name="photo" size="25" />
        <input type="submit" name="submit" value="Submit" />
    </form>

php (accept-file.php)
//if they DID upload a file...
if($_FILES['photo']['name'])
{
    //if no errors...
    if(!$_FILES['photo']['error'])
    {
        //now is the time to modify the future file name and validate the file
        $new_file_name = strtolower($_FILES['photo']['tmp_name']); //rename file
        if($_FILES['photo']['size'] > (1024000)) //can't be larger than 1 MB
        {
            $valid_file = false;
            $message = 'Oops!  Your file\'s size is to large.';
        }

        //if the file has passed the test
        if($valid_file)
        {
            //move it to where we want it to be
            move_uploaded_file($_FILES['photo']['tmp_name'], 'uploads/'.$new_file_name);
            $message = 'Congratulations!  Your file was accepted.';
        }
    }
    //if there is an error...
    else
    {
        //set that to be the returned message
        $message = 'Ooops!  Your upload triggered the following error:  '.$_FILES['photo']['error'];
    }
}

//you get the following information for each file:
$_FILES['field_name']['name']
$_FILES['field_name']['size']
$_FILES['field_name']['type']
$_FILES['field_name']['tmp_name']


A: This code is for you reference:
<?php

  $allowedExts = array("gif", "jpeg", "jpg", "png");
  $temp = explode(".", $_FILES["file"]["name"]);
  $extension = end($temp);

  if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/pjpeg") || ($_FILES["file"]["type"] == "image/x-png") || ($_FILES["file"]["type"] == "image/png")) && ($_FILES["file"]["size"] < 20000) && in_array($extension, $allowedExts))  {

    if ($_FILES["file"]["error"] > 0) {
        echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
    } else {
        echo "Upload: " . $_FILES["file"]["name"] . "<br>";
        echo "Type: " . $_FILES["file"]["type"] . "<br>";
        echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
        echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";

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


A: I have now managed to create a system, I figured it out by testing all your answers! :) Also took some time to read docs on php.net ;)
Best regards, Kristian
