How to pass the new value in the input field?

Apparently, I do not know php... (((
There is a simple form that accepts a field from the database that stores the file name of the image. Then, in the same form and choose a new image file and copy it to the folder where you stored all the pictures for the website.
The following scripts this task is successfully performed.
The script for the form itself
<form action="img-upload.php" enctype="multipart/form-data" method="POST" name="form_upload">
 <?php img_data_read(); ?> // select data from DB and pass the value of a field in a variable named $ImgName - does everything well!
 <div class="form-group row h-20">
 <label for="logo" class="col-2 col-form-label my-auto">Logo and favicon</label>
 <div id="image" class="col-1 my-auto">
 <img class"img-fluid" src="./images/<?php echo $ImgName; ?>" style="width: 10vh; height: auto;">
</div>
 <div class="col-4 my-auto">
 <input class="form-control site-name" type="text" name="Logo" value="<?php echo $ImgName; ?>" id="Logo" readonly>
</div>
 <div class="col-5 my-auto">
 <label><input id="file" name="file" type="file" /></label>
 <label><input name="button" type="submit" value="Save" /></label>
</div>
 <?php echo "Loaded file name" . $_FILES['file']['name']; ?>
 </div>

Here note the penultimate line of code that would print the name of the uploaded file, but does not display anything at all.
Script img-upload.php - action for ^
require 'functions.php';
header('Location: admin.php');
$extensions = array('jpg', 'jpeg', 'png', 'gif'); // array of allowed extensions
$upload_dir = 'images'; // folder to download
if(!empty($_POST['button'])) {
 $message = uploadHandle(8, $extensions, $upload_dir);
 echo $message = $message['error'] ? $message['error'] : $message['info'];
}

here we use the header to return to any page to initiate a script. The called function uploadHandle contained in the file functions.php:
uploadHandle function($max_file_size = 1024, $valid_extensions = array(), $upload_dir = '.') {
 $error = null;
 $info = null;
 $max_file_size *= 1048576; // maximum file size in bytes: 1,048,576 bytes = 1 MB
 if ($_FILES['file']['error'] === UPLOAD_ERR_OK) {
 // check file extension
 $file_extension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
 if (in_array(strtolower($file_extension), $valid_extensions)) {
 // check file size
 if ($_FILES['file']['size'] < $max_file_size) {
 $file_name = $_FILES['file']['name']; // get file name
 $destination = './' . $upload_dir . '/' . $file_name;
 if (move_uploaded_file($_FILES['file']['tmp_name'], $destination)) $info = 'File' . $file_name . 'uploaded successfully';
 else $error = 'failed to upload file';}
 else $error = 'file Size is more than allowed';}
 else $error = 'the file has an incorrect extension';}
 else {
 // array of errors
 $error_values = array(
 UPLOAD_ERR_INI_SIZE => 'the file Size is greater than allowed by upload_max_filesize Directive in php.ini',
 UPLOAD_ERR_FORM_SIZE => 'the file Size exceeds the value specified in the MAX_FILE_SIZE',
 UPLOAD_ERR_PARTIAL => 'the File was only partially uploaded',
 UPLOAD_ERR_NO_FILE => 'you did Not select file to upload',
 UPLOAD_ERR_NO_TMP_DIR => 'Not found' folder for temporary files',
 UPLOAD_ERR_CANT_WRITE => 'failed to write file to disk');
 $error_code = $_FILES['file']['error'];
 if (!empty($error_values[$error_code])) $error = $error_values[$error_code];
 else $error = 'it was something strange';
}
 return array('info' => $info, 'error' => $error);
}

On every test, you can not pay attention, they are, in principle, almost all the work.
Total result: the file selected and copied to the desired folder.
Task: to replace the (probably requires ajax) the value of the variable $ImgName in
March 12th 20 at 08:10
0 answer

Find more questions by tags PHP