Hi I am facing a problem while uploading two files using php. I have this html input form with two files field
<form class="form-group" method="post" enctype="multipart/form-data">
<input type="file" accept=".jpg, .jpeg, .png" id="img" name="displaypic" required/>
<input type="file" accept=".pptx" name="presentation" required>
<button name="submit>Submit</submit>
</form>
This is my php code. Here I take the file data from the form but only the first one is uploaded, second file is not.
<?php
if(isset($_POST['submit'])){
$file = $_FILES['displaypic'];
$fileName = $_FILES['displaypic']['name'];
$tempName = $_FILES['displaypic']['tmp_name'];
$size = $_FILES['displaypic']['size'];
$error = $_FILES['displaypic']['error'];
$format = $_FILES['displaypic']['type'];
$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));
$allowed = array('jpg', 'jpeg','png');
if(in_array($fileActualExt, $allowed)) {
if ($error === 0) {
if ($size<2e6) {
$newname = $tid.".".$fileActualExt;
$location = 'displays/'.$newname;
move_uploaded_file($tempName,$location);
}}}
Similarly when I write the same code for file two it doesn't work. Only the first file is uploaded not the second file.
$file_ppt = $_FILES['presentation'];
$fileName = $_FILES['presentation']['name'];
$tempName = $_FILES['presentation']['tmp_name'];
$size = $_FILES['presentation']['size'];
$error = $_FILES['presentation']['error'];
$format = $_FILES['presentation']['type'];
$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));
$allowed = array('pptx');
if(in_array($fileActualExt, $allowed)) {
if ($error === 0) {
if ($size<10e6) {
$newname = $tid.".".$fileActualExt;
$location = 'presentations/'.$newname;
move_uploaded_file($tempName,$location);
}}}
}
?>
xfiles[]or whatever$errorcontains.