PHP image validation script -


i make image validation script making news items. searched other examples php knowlegde isn't great implement it.

html:

<input class="form-control contact-control" type="hidden" name="max_file_size" value="1000000"> <input class="form-control contact-control" type="file" name="image" id="image"> 

php:

$news_item = $_post['item']; $news_date = $_post['date']; $news_text = $_post['text']; $max_file_size = 1000000; $path = ("../../../database/img/"); $news_image = $_files['image']['name'];  $image_size = $_files['image']['size']; $image_type = $_files['image']['type'];      if(!empty($news_item) && !empty($news_date) && !empty($news_text) && !empty($news_image)) {         if(($image_type == 'image/jpeg') || ($image_type == 'image/png') || ($image_type == 'image/gif') && ($image_size > 0) && ($image_size <= $max_file_size)) {             if($_files['file']['error'] == 0) {                 $target = $path . $news_image;                 if(move_uploaded_file($_files['image']['tpm_name'], $target)) {                     $query_news = "insert news(item, date_item, news_text, photo) values('".$news_item."', '".$news_date."', '".$news_text."', '".$uploaded_dir.$news_image."')";                     mysql_query($query_news);                 } else {                     $update_news = "update news set item = '".$news_item."', date_item = '".$news_date."', news_text = '".$news_text."', photo = '".$uploaded_dir.$news_image."'";                     mysql_query($update_news);                 }             }         } else {             echo 'the screenshot must gif, jpeg or png image no ' . 'less ' . ($max_file_size / 1000000) . 'mb in size.';         }          @unlink($_files['image']['tmp_name']);      } else {         echo 'please enter alll of information.';     } 

there isn't added new row of information database , no image stored. suspect 1 of if statement goes false.

first, don't need remove temp file @unlink($_files['image']['tmp_name']);. delete line.

second, script exposed sql injection because use post values directly without filtration.

third, have type here: if(move_uploaded_file($_files['image']['tpm_name'], $target)) {. array key right name tmp_name.


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -