0 votes

PHP">php error "Warning: undefined array key " in image upload with $imgssName = $_FILES['img']['name'];

<?php

include'head.php';
include 'connect.php';
$title = $_POST['title'];
$info = $_POST['info'];
$text = $_POST['text'];
// varabls Uploud
$imgssName = $_FILES['img']['name'];
$imgSize = $_FILES['img']['size'];
$imgTmp = $_FILES['img']['tmp_name'];
$imgType = $_FILES['img']['type'];

// Chek extensions Img
$file_parts = pathinfo($imgssName);

$file_parts['extension'];
$cool_extensions = Array ('jpeg', 'jpg', 'JPG', 'png', 'PNG', 'gif', 'JPEG', 'GIF', 'pdf','psd');
if (in_array($file_parts['extension'], $cool_extensions)){
// Chek Size Img
$img = rand(0, 100000000) . '_' . $imgssName;
move_uploaded_file($imgTmp, "uploads/imgs//" . $img);
$stmt = $con->prepare("INSERT INTO 
            news(title,info,text,img,date) VALUES (:btitle, :binfo, :btext, :bimg, now()  )");
$stmt->execute(array(
                'btitle' => $title,
                'binfo' => $info,
                'btext' => $text,
                'bimg' => $img,
                    ));

?>

HolaDevs.com

HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by:

X