PHP image upload

This is my image upload solution:

<form action="upload.php" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Upload Image" name="submit">
    <br>
    By clicking the Upload button you accept that you are the owner of the file.
</form>

 <?php
$target_dir = "./i/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$ext = pathinfo(basename($_FILES["fileToUpload"]["name"]), PATHINFO_EXTENSION);
$uploadOk = 1;
$FILENAME = hash_file("md5",$_FILES["fileToUpload"]["tmp_name"]).".".$ext;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
    $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
    if($check !== false) {
        $uploadOk = 1;
    } else {
        echo "<h5>File is not an image.</h5>";
        $uploadOk = 0;
    }
	// Check if file already exists
	if (file_exists("./i/".$FILENAME)) {
	    echo "<h5>Sorry, file already exists.</h5>";
	    create_output($FILENAME);
	    $uploadOk = 0;
	}
	// Check file size
	if ($_FILES["fileToUpload"]["size"] > 5000000) {
	    echo "<h5>Sorry, your file is too large.</h5>";
	    $uploadOk = 0;
	}
	// Allow certain file formats
	if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
	&& $imageFileType != "gif" && $imageFileType != "svg" ) {
	    echo "<h5>Sorry, only JPG, JPEG, SVG PNG & GIF files are allowed.</h5>";
	    $uploadOk = 0;
	}
	// Check if $uploadOk is set to 0 by an error
	if ($uploadOk == 1){
	    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], "./i/".$FILENAME)) {
		echo "<h5>The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.</h5>";
		create_output($FILENAME);
	    } else {
		echo "<h5>Sorry, there was an error uploading your file.</h5>";
	    }
	}
}else{
	echo "<br><br><br><br>Recent uploaded images:<br>";
	$files = scandir($target_dir);
	$count = 0;
	foreach($files as $result) {
		if( $result != "." && $result !=".."){
    			echo "\n<a href='http://scheinast.eu/i/$result' target='_blank'><img src='http://scheinast.eu/i/$result' style='width:304px;height:228px'></a>";
    		}
    		if($count > 10){break;}++$count;
	}

}


function create_output($FILE){
echo "<a href='http://scheinast.eu/i/$FILE'>http://scheinast.eu/i/$FILE</a>";
echo "<a href='http://scheinast.eu/i/$FILE'><img src='http://scheinast.eu/i/$FILE'></img></a>";
}

?> 
</body>
</html>

The name its stored is always an md5 hash of the file to avoid duplicate files.

PHP crawl example

This is a little example how to crawl a web page with PHP, in this example I crawl my own page with XPATH to get all titles.

<?php
# turn erros of
libxml_use_internal_errors(true);
# creat DomDocument Object
$DOM = new DomDocument;
# load the THML
$DOM->loadHTMLFile("/");
# creat DomXPath Object
$XPATH = new DomXPath($DOM);
# get all titles with XPATH
$mynodes = $XPATH->query("//article//header//h1");
# print result
foreach ($mynodes as $i => $mynodes) {
    echo "[$i] => '", $mynodes->nodeValue, "'n";
}
?>

This is our result, this are the matches from the XPATH:

[0] => 'create multiple file in shell with touch'
[1] => 'Format current Date in Perl and Bash'
[2] => 'Perl Print Benchmark'
[3] => 'Perl simple Data Dumper for references'
[4] => 'Arduino C Program LED Blink'
[5] => 'Perl Constant Benchmark'
[6] => 'Benchmark Debug perl'
[7] => 'Programmier-Einleitung in C/C++'
[8] => 'perl debug output'
[9] => 'crontab via script'

To see this in Perl click: Perl crawl example.