I am trying to learn uploading images via PHP. I was trying to upload the image, excluding validation code for format and size and suddenly this error occurred. I tried changing the name attribute of tag. But it doesn't solved my problem.
My code is:
<?php
if($_SERVER['REQUEST_METHOD'] == "POST") {
$target_dir = "../images/images_channel/";
$target_file = $target_dir . basename($_FILES['image']['name']);
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
$new_image_name = $target_dir . "abc" . "." . pathinfo($target_file,PATHINFO_EXTENSION);
if(move_uploaded_file($_FILES["image"]["tmp_name"], $new_image_name)) {
echo "success";
}
else {
echo "fail";
}
}
?>
<form action="" method="POST">
<input type="file" name="image" id="image" />
<input type="submit" value="Submit" />
</form>
Two errors are:
Notice: Undefined index: image in E:\wamp\www\new22\alfasahah\admin\check.php on line 4
Notice: Undefined index: image in E:\wamp\www\new22\alfasahah\admin\check.php on line 7