Undefined Index while uploading file
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 !!';
}
}
?>
PHP Undefined index error $_FILES?
first: try to strict programming
error_reporting(E_ALL | E_STRICT);
also you must use isset for check is index for array available or not
if (isset($_POST['submitbtn']) && isset($_FILES['avatar'])) {
// ...
}
also check php configuraion
file_uploads "1"
upload_max_filesize "2M"
post_max_size "8M"
max_file_uploads 20
post max size must be larger than upload max file size.
also as guys said check form enctype
$_FILES undefined index : file
Correct way is:
<?php
if(isset($_POST['submit'])){
echo $_FILES['file']['error'];
}
?>
<form action="uploads.php" method = "POST" enctype="multipart/form-data">
<input name="file" type="file"><br>
<input type="Submit" value="Submit" name='submit'/>
</form>
You are echoing "$_FILES['file']['error']
" before form submit. echo input type file value or something after form submission.
php upload error, undefined index userfile
undefined index userfile, that means when the page loads there is no $_FILES['imageupload'] you need to submit the page to have that variable
<?php
if(isset($_POST['save'])){
$path="upload/";
$name = $_FILES['imageupload']['name'];//Name of the File
$temp = $_FILES['imageupload']['tmp_name'];
if(move_uploaded_file($temp, $path . $name)){
echo "success";
}else{
echo "failed";
}
}
?>
<form method="post" action="" enctype="multipart/form-data">
<input type="file" name="imageupload">
<input type="submit" name="save" value="submit">
</form>
$_FILES undefined index error
Try setting the proper enctype in your form tag:
<form action="wpis.php" method="POST" enctype="multipart/form-data">
Related Topics
How to Search Array for Multiple Values in PHP
Mysqli - Fetch_Array Error Call to a Member Function Fetch_Array() on a Non-Object MySQLi
Disable Template Caching for Development in Opencart 3
Get the Values of 2 HTML Input Tags Having the Same Name Using PHP
How to Connect to a Tor Hidden Service Using Curl in PHP
Regular Expression Preg_Quote Symbols Are Not Detected
PHP Code Formatter/Beautifier and PHP Beautification in General
PHP Session with an Incomplete Object
Using Named Parameters with Pdo for Like
Destroy Session on Window Close
Nested PHP Ternary Trouble: Ternary Output != If - Else
PHP Sending Variables to File_Get_Contents()
Increase the Limit of File Upload Size in Heroku While Uploading to Dropbox
How to Deploy Correctly When Using Composer's Develop/Production Switch
PHP Get Name of Current Directory
Show Progressbar While Loading Pages Using Jquery Ajax in Single Page Website