This is my error:
Notice: Undefined index: file in C:\xampp\htdocs\Project\Template1\users\index.php on line 21 Notice: Undefined index: file in C:\xampp\htdocs\Project\Template1\users\index.php on line 23 please uploaded
How to get rid of it?
Html Code:
<form action="index.php" method="post" enctype="multipart/form-data">
<input type="file" name="file" id="file"><br><br>
<input type="submit" value="submit" name="submit">
</form>
Php Code:
<?php
$name = $_FILES['file']['name'];
$temp_name = $_FILES['file']['temp_name'];
if (isset($name)) {
if (!empty($name)) {
$location = '../uploads/';
}
if (move_uploaded_file($temp_name, $location.$name)) {
echo 'uploaded';
}
} else {
echo 'please uploaded';
}
?>
Make sure you have set form attributeenctype="multipart/form-data"
.
This attribute help you to get files from user.
<form action="PATH" method="post" enctype="multipart/form-data"></form>
Change your PHP script as below and try
<?php
if(isset($_POST['submit'])){
$name = $_FILES['file']['name'];
$temp_name = $_FILES['file']['tmp_name'];
if(isset($name) and !empty($name)){
$location = '../uploads/';
if(move_uploaded_file($temp_name, $location.$name)){
echo 'File uploaded successfully';
}
} else {
echo 'You should select a file to upload !!';
}
}
?>
this happens due to the size of the file :
max_execution_time
= 300max_input_time
= 240post_max_size
= 128Mupload_max_filesize
= 128M
in your php.ini file you should change above codes according to your requirement...
Do a check around your PHP code block checking if either the submit button has been pressed or ifisset($_FILES['file'])
. This should remove your errors. They pop up because the $_FILES['file'] isn't populated before the submit button is pressed.
Usually, the problem is forgetting to add this line as a form tag attribute.
enctype="multipart/form-data"
The enctype attribute specifies how the form-data should be encoded when submitting it to the server.
Note: The enctype attribute can be used only if method="post".
Spelling mistake:
<?php
$name = $_FILES['file']['name'];
$temp_name = $_FILES['file']['tmp_name']; // tmp_name
if(isset($name)){
if(!empty($name)){
$location = '../uploads/';
}
if(move_uploaded_file($temp_name, $location.$name)){
echo 'uploaded';
}
} else {
echo 'please uploaded';
}
?>
$upload_dir="../uploads";
$target_file="";
$tmp_file="";
if(isset($_POST['submit']))
{
$tmp_file=$_FILES['file']['tmp_name'];
$target_file=basename($_FILES['file']['name']);
if(move_uploaded_file($tmp_file, $upload_dir."/".$target_file))
{
echo "File uploaded <br />";
}
else {
echo "Something went Wrong !!<br/>";
}
}
if you are getting Notice: Undefined index: zip_file in error message most of the time, While uploading any file to server using php, Then here is the solution for this. only you need to mention enctype type in form tag.
<form method="post" action="" name="login" enctype="multipart/form-data">
Check if file_uploads is enabled on your php.ini
file_uploads = On
the solid solution to this problem is to use
if(isset($_POST['submit-button'])){
$option="";
$option=$_POST["anbieterin_geburtstag_month"];
echo $option;
}
always use isset function
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
HTML (English "hyper text markup language" - hypertext markup language) is a special markup language that is used to create sites on the Internet.
Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone.
https://www.w3.org/html/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.