<?php 
$name= $_FILES['fname']['name'];
echo $name;
?>
<form action="test.php" method="POST" enctype=" multipart/form-data">
    Select file: <br><br>
    <input type="file" name="fname"><br><br>
    <input type="submit"><br>
</form>
            Asked
            
        
        
            Active
            
        
            Viewed 200 times
        
    -4
            
            
         
    
    
        JRG
        
- 4,037
- 3
- 23
- 34
 
    
    
        Raktim Prabal
        
- 11
- 2
- 
                    ` ` check it and tell – Alive to die - Anant Jul 30 '17 at 18:22
2 Answers
0
            
            
        <?php
if(isset($_POST["submit"])) {
$name= $_FILES['fname']['name'];
echo $name;
}
 
    
    
        Hossein Piri
        
- 716
- 1
- 7
- 15
- 
                    error (Undefined error ) is gone, but the code isn't showing the name of the file that I've chosen. – Raktim Prabal Jul 30 '17 at 18:32
0
            This file must be save as test.php     
 <?php 
    if(isset($_POST['formFile'])){
    $name= $_FILES['fname']['name'];
    echo $name;
    }
else{
echo "No file selected";
}
    ?>
    <form action="test.php" method="POST" enctype="multipart/form-data">
        Select file: <br><br>
        <input type="file" name="fname"><br><br>
        <input type="submit" name="formFile"><br>
    </form>
 
    
    
        Lekens
        
- 1,823
- 17
- 31
- 
                    Yes, I've saved it as test.php Now error (Undefined index ) is gone, but code isn't showing the name of the file that I've chosen – Raktim Prabal Jul 30 '17 at 18:35
- 
                    
- 
                    
- 
                    I tried a image file of size 215 kb and tried text file of size 3kb too. but the name of the file is not showing – Raktim Prabal Jul 30 '17 at 19:25
- 
                    It works perfectly on my machine. Please copy that code as it is and paste in ur code editor and save as a .php file. Not a .html file – Lekens Jul 30 '17 at 20:40
- 
                    
- 
                    Thanks, now its working, I've saved it as a .php file. but what is my mistake? – Raktim Prabal Jul 31 '17 at 14:38
-