Why do I keep seeing the undefined index error for line 13 ('file')? - indexing

I am trying to create a simple drag and drop page using php. When I click the "submit" button, I get an error: Notice: Undefined index: file in C:\xampp\htdocs\phpfiles\DragAndDrop\includes\gallery-upload.inc.php on line 13. Why is it not reading the "file" index from the htmlphp?
Here is the HTML and PHP code:
enter code here
<!--continuted from HTML page-->
</section>
<?php
$_SESSION['username'] = "Admin";
if (isset($_SESSION['username'])) {
echo '<div class="gallery-upload">
<form action="includes/gallery-upload.inc.php" method="post" enctype="mutipart/form-data">
<input type="text" name="filename" placeholder="File Name...">
<input type="text" name="filetitle" placeholder="Image Title...">
<input type="text" name="filedesc" placeholder="Image description...">
<input type="file" name="file">
<button type="submit" name="submit">Upload</button>
</form>
</div>';
}
?>
</main>
</body>
</html>
<!--and the php page-->
<?php
if (isset($_POST['submit'])) {//checks submit form and posts the info
$newFileName = $_POST['filename'];
if (empty($_POST['filename'])) { //if filename is emptly
$newFileName = "gallery"; //if filename is empty, generates name
} else {
$newFileName = strtolower(str_replace(" ", "-", $newFileName)); //if spaces are in the name, creates stringholder
}
$imageTitle = $_POST['filetitle'];
$imageDesc = $_POST['filedesc'];
$file = $_FILES['file'];
}
?>

You have a typo:
mutipart/form-data
Should be
multipart/form-data

Related

Undefined index eror in $_POST

When $_POST submitted anythings working well, But i got this eror Notice: Undefined index: trackingbymobile in /home/../sot_options.php on line ۱۸
if (isset($_POST['optionsformbtn'])&& ($_POST['optionsform'] == 'optionsform')&& ($_POST['trackingbymobile']!=="")){
$wpdb->query($wpdb->prepare( "UPDATE $sotoptions SET option_value = %s WHERE option_name = %s", $_POST['trackingbymobile'], 'trackingbymobile' ));
}
<form name="optionsform" id="optionsform" action="" method="POST">
<input type="checkbox" name="trackingbymobile" id="trackingbymobile">
<input class="sotadminpanelbtn" type="submit" name="optionsformbtn">
</form>

Adding a progress bar when Uploading local files using API

API Documentation: https://doodstream.co/api-docs#local-upload
My code seems working but there's no indicator how many time left before download is finished
HTML
<form enctype="multipart/form-data" action="upload.php" id="form" method="post" align="center">
<div>
<label>Custom File Name: </label><br>
<input type="text" placeholder="File Name" name="fname" minlength="3" required/>
</div>
<br><br>
<div>
<label>Select video: </label><br>
<input type="file" name="file" accept="video/*" required/><br>
</div>
<br>
<input name="submit" type="submit" value="Upload"/>
</form>
upload.php
<?php
if(!empty($_FILES)){
$tempfile = $_FILES["file"]["tmp_name"]; //Temporary file location on server
$fname = $_POST["fname"]; //Custom File name input
$type = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION); //File extention
$name = $fname . '.' . $type; //Complete file name with extention to be used in API
require('doodstream.php'); //Unofficial Library from GitHub
$ds = new DoodstreamAPI();
$key = "MY-API-KEY"; //Insert API key here
$ds->Setup($key);
$result = $ds->Upload($tempfile, $type, $name);
print_r($result);
}
else{
die('No file uploaded');
}
?>
Is there any method to make this possible? I just read the documentation and there's only an "After upload response"

Bootstrap 4.3.1 dropdown login form redirect upon success

I am building a site where users can login via a Bootstrap Dropdown, i did have it working, it would log user in and refresh the whole page with login session BUT if user entered wrong creds it wouldn't stay open and alert them. I got around this by putting the login form in an iframe in the dropdown but it's no longer starting the session - any ideas please? I'm trying to not be vague so here is the code in the iframe and the actual URL below that - thank you :)
<div class="header_login_form_dropdown">Login</div>
<form name="login" action="" method="post" class="form">
<div class="form-group">
<label class="login_form_dropdown" for="lopc_username">Email</label>
<input type="email" class="form-control" id="lopc_username" placeholder="email#company.com" name="lopc_username">
</div>
<div class="form-group">
<label class="login_form_dropdown" for="lopc_password">Password</label>
<input type="password" class="form-control" id="lopc_password" name="lopc_password">
</div>
Forgot password
<button type="submit" name="submit" class="btn btn-primary login_btn">LOGIN</button>
<div style="padding:15px 0 15px 0; border-top: 2px solid #eee; font-size: 14px; color: #696969">
New customer? Register here
</div>
<?php
if (isset($_POST['submit']))
{
include('../265451/92631043.php');
$lopc_username = mysqli_real_escape_string($conn,$_POST['lopc_username']);
$lopc_password = mysqli_real_escape_string($conn,(md5($_POST['lopc_password'])));
$lopc_last_login = date("Y-m-d H:i:s");
$query = "SELECT * FROM lopc_reg_users WHERE lopc_username = '$lopc_username' AND lopc_password = '$lopc_password' ";
$result = mysqli_query($conn,$query);
if(mysqli_num_rows($result) == 1)
{
$_SESSION['lopc_username'] = $_POST['lopc_username'];
$lopc_username = $_SESSION['lopc_username'];
$query2 = "UPDATE lopc_reg_users SET lopc_last_login = '$lopc_last_login' WHERE lopc_username = '$lopc_username' ";
$result2 = mysqli_query($conn,$query2);
//header("Location: ".$_SERVER['PHP_SELF']);
?>
<script>
window.parent.location.reload();
</script>
<?php
exit;
}
else
{
echo '<div class="login_error">Username or password does not exist.</div>';
}
}
?>
</form>
https://littleorangeprinting.co.uk/2021
Login: test#test.com
Pass: testing4321

Custom multilingual inputs - opencart

What is the pattern for creating a multilingual input in opencart for admin side.
For example I want to have two List Description Limit inputs, one for each language.
Like in this image. So I can control from admin side the list limit for every language.
Currently I use this pattern to create a custom input, but this is not language dependent:
File: admin/view/template/extension/theme/theme_default.tpl
<fieldset>
<div class="form-group required">
<label class="col-sm-2 control-label" for="inputId"><span data-toggle="tooltip" title="<?php echo $help_inputName; ?>"><?php echo $label_inputName; ?></span></label>
<div class="col-sm-10">
<input type="text" name="theme_default_inputName" value="<?php echo $theme_default_inputName; ?>" placeholder="<?php echo $label_inputName; ?>" id="inputId" class="form-control" />
<?php if ($error_inputName) { ?>
<div class="text-danger"><?php echo $error_inputName; ?></div>
<?php } ?>
</div>
</div>
</fieldset>
File: admin/language/en-gb/extension/theme/theme_default.php
//Language strings
$_['help_inputName'] = 'helpTxt';
$_['label_inputName'] = 'labelForInput';
$_['error_inputName'] = 'errorForInput';
File: admin/controller/extension/theme/theme_default.php
//Language strings
$text_strings = array(
'help_inputName',
'label_inputName',
'error_inputName'
);
foreach ($text_strings as $text) {
$data[$text] = $this->language->get($text);
}
//Error handling
if (isset($this->error['inputName'])) {
$data['error_inputName'] = $this->error['inputName'];
} else {
$data['error_inputName'] = '';
}
//Custom field
if (isset($this->request->post['theme_default_inputName'])) {
$data['theme_default_inputName'] = $this->request->post['theme_default_inputName'];
} elseif (isset($setting_info['theme_default_inputName'])) {
$data['theme_default_inputName'] = $setting_info['theme_default_inputName'];
} else {
$data['theme_default_inputName'] = "customText";
}
//Validation
if (!$this->request->post['theme_default_inputName']) {
$this->error['inputName'] = $this->language->get('error_inputName');
}

execute sql query on button click

nw_check.php
<?php
$con = mysql_connect("localhost","root","12345");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
?>
<html>
<body>
<form method="POST" action="nw_check_exec.php">
<input type="button" name="nw_update" value="NW_Update"/>
</form>
</body>
</html>
nw_check_exec.php
<?php
if(isset($_POST['nw_update'])){
echo("You clicked button one!");
//and then execute a sql query here
}
else {
echo" dhur";
}
?>
but for some reason the echo in the nw_check_exec.php is not being executed. please could you help.
I think it's because the input type is a "button" and should be a submit:
<input type="submit" name="nw_update" value="NW_Update"/>