My Use case: On my server I have 4 folders, On upload page I need to list those folder in drop-down. User first select multiple image files stored in local storage and select a desired server folder from drop-down where he/she wants to upload and then click on upload button.
I have coded it in PHP accordingly, I have achieve the above use case but with single image only. I am not able to select the multiple image files.
Below is my upload.php file:
<?php
session_start();
if(!isset($_SESSION['user_id'])){
header('Location: login.php');
exit;
} else {
if ($_POST['variable'] == '')
{
$variable = './'; // default folder
}
else
{
$variable = $_POST['variable'] ;
}
$folder = $variable;
$uploadpath = "$folder/";
$max_size = 20000;
$alwidth = 9000;
$alheight = 8000;
$allowtype = array('bmp', 'gif', 'jpg', 'jpe', 'png', 'webp');
if(isset($_FILES['fileup']) && strlen($_FILES['fileup']['name']) > 1) {
$uploadpath = $uploadpath . basename( $_FILES['fileup']['name']);
$sepext = explode('.', strtolower($_FILES['fileup']['name']));
$type = end($sepext);
list($width, $height) = getimagesize($_FILES['fileup']['tmp_name']);
$err = '';
if(!in_array($type, $allowtype)) $err .= 'The file: <b>'. $_FILES['fileup']['name']. '</b> not has the allowed extension type.';
if($_FILES['fileup']['size'] > $max_size*1000) $err .= '<br/>Maximum file size must be: '. $max_size. ' KB.';
if(isset($width) && isset($height) && ($width >= $alwidth || $height >= $alheight)) $err .= '<br/>The maximum Width x Height must be: '. $alwidth. ' x '. $alheight;
if($err == '') {
if(move_uploaded_file($_FILES['fileup']['tmp_name'], $uploadpath)) {
echo 'File: <b>'. basename( $_FILES['fileup']['name']). '</b> successfully uploaded:';
echo '<br/>File type: <b>'. $_FILES['fileup']['type'] .'</b>';
echo '<br />Size: <b>'. number_format($_FILES['fileup']['size']/1024, 3, '.', '') .'</b> KB';
if(isset($width) && isset($height)) echo '<br/>Image Width x Height: '. $width. ' x '. $height;
echo '<br/><br/>Image address: <b>http://'.$_SERVER['HTTP_HOST'].rtrim(dirname($_SERVER['REQUEST_URI']), '\\/').'/'.$uploadpath.'</b>';
}
else echo '<b>Unable to upload the file.</b>';
}
else echo $err;
}
}
?>
<style>
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
margin: 50px auto;
text-align: center;
width: 800px;
}
h1 {
font-family: 'Passion One';
font-size: 2rem;
text-transform: uppercase;
}
label {
width: 150px;
display: inline-block;
text-align: left;
font-size: 1.5rem;
font-family: 'Lato';
}
input {
border: 2px solid #ccc;
font-size: 1.5rem;
font-weight: 100;
font-family: 'Lato';
padding: 10px;
}
form {
margin: 25px auto;
padding: 20px;
border: 5px solid #ccc;
width: 500px;
background: #eee;
}
div.form-element {
margin: 20px 0;
}
button {
padding: 10px;
font-size: 1.5rem;
font-family: 'Lato';
font-weight: 100;
background: yellowgreen;
color: white;
border: none;
}
p.success,
p.error {
color: white;
font-family: lato;
background: yellowgreen;
display: inline-block;
padding: 2px 10px;
}
p.error {
background: orangered;
}
</style>
<div style="margin:1em auto; width:333px; text-align:center;">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"
enctype="multipart/form-data">
Upload File: <input type="file" name="fileup" /><br/>
<select name="variable" />
<option value=null selected="selected">Select a folder</option>
<html>
<body>
<form name="input" action="upload.php" method="post" onchange="this.form.submit()">
<?php
$dirs = glob("*", GLOB_ONLYDIR);
foreach($dirs as $val){
echo '<option value="'.$val.'">'.$val."</option>\n";
}
?>
</select>
<input type="submit" name='submit' value="UPLOAD" />
</div>
</form>
<button>
<a href="logout.php" tite="Logout">LOGOUT</a></button>
</div>
</body>
</html>
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.