This question is for about 1 year ago, but maybe still another persons have this problem, so i put a solution here, it worked for me, hope works for you too
<?php
if(isset($_POST['submit']) && !empty($_FILES['ufile']['name'])) {
$fileext = explode(".",$_FILES['ufile']['name']);
$fileext = $fileext[sizeof($fileext)-1]; // fetching extension of temp file
$filename = $_FILES['ufile']['name'];
if (strtolower($fileext) == "jpg" || strtolower($fileext) == "jpeg" || strtolower($fileext) == "gif" || strtolower($fileext) == "png") {
$f=fopen($_FILES['ufile']['tmp_name'],'r');
$content="";
echo $f;
while(!feof($f))
{
$content .= fgets($f);
}
/* Add the words(tages) or any suspect words you wanna to block uploading based on them */
$forbidden = array("html",
"php",
"form",
"script",
"java",
"div",
"table",
"span",
"tr",
"td",
"th",
"submit",
"body",
"head",
"var",
"function");
foreach($forbidden as $forbidword)
if(strpos($content, $forbidword) !== false)
die("Error: Malicious image cannot upload!");
if (move_uploaded_file($_FILES['ufile']['tmp_name'], "./".$filename)) {
echo "
The file was uploaded succesfully <br/>
Details : <br>
Link : ".$filename."<br />
File Name : ".$filename." <br>
File Size : ".($_FILES['ufile']['size']/1000)." KB <br>
File Type : ".$_FILES['ufile']['type'];
} else{
echo "An unexpected error : ".error_log();
}
} else {
echo "Only file with this extentions allow to upload :"."JPG, JPEG, GIF, PNG";
}
}
?>
<!DOCTYPE html>
<html>
<body>
<form action="" method="POST" name="addnews" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="4000000" />
<label class="title">Choose an image file:
<input type="file" name="ufile" />
</label>
<br />
<input name="submit" type="submit" value="Upload Media" />
</form>
</body>
</html>
unlink()
method. – Araliaceous