1

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

1 Answer 1

1

You need to add to the form enctype="multipart/form-data"

<form action="" enctype="multipart/form-data" method="POST">
    <input type="file" name="image" id="image" />
    <input type="submit" value="Submit" />
</form>

see php.net

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.