Мнение за image upload script

qazxsw

Registered
Здравейте, това е един скрипт който направих вчера и бих желал да чуя вашето мнение относно дали всичко му е в ред и дали има други security checks които трябва да приложа. Мерси :)

PHP:
<?php

//When the form is submited
if(isset($_POST['upload'])){

	//Set some default variables
	$upload_dir = "uploads/";
	$upload_file = basename($_FILES['image']['name']);
	$extension = preg_replace('/^.*\.([^.]+)$/D', '$1', $upload_file);
	
	//Create some arrays
	$error_array  = array(); //It will store all errors that occured
	$allowed_files = array("jpg","png","gif");
	
	//Check if any errors occured during upload and if there are, show them to the user
	if($_FILES['image']['error'] > 0){
		array_push($error_array, $_FILES['image']['error']);}
	
	//Check if the uploaded file is bigger than 1MB
	if($_FILES['image']['size'] > 1048576){
		array_push($error_array,"Maximum upload file size is 1MB!");}
	
	//Get information about the file, ONLY if file is uploaded and its image
	if($_FILES['image']['error'] != 4 && in_array($extension, $allowed_files)){	
		$image_info = getimagesize($_FILES['image']['tmp_name']);}
	
	//Check the uploaded file extension
	if( !in_array($extension, $allowed_files) ){
		array_push($error_array, "Only .JPG , .GIF AND .PNG files allowed!");}

	//Check the file mime type
	if( isset($image_info) && in_array($extension, $allowed_files) ){ 
		if( $image_info['mime'] != 'image/gif' && $image_info['mime'] != 'image/jpeg' && $image_info['mime'] != 'image/png'){
			array_push($error_array, "Somethings wrong with your image.");}}
		
	//Check if there are any errors so far, and if there are show them to the user and stop the script
	if( !empty($error_array) ){
		foreach($error_array as $error){
			echo $error."<br />";}}
			
	else{
	//Move the uploaded file to the upload folder
	if(move_uploaded_file($_FILES['image']['tmp_name'], $upload_dir.$upload_file)){
		echo "File uploaded successfully.";}}

}

?>
 

Back
Горе