1

I want to get folder name from my computer in PHP code. I got the following piece of information, on searching on stackoverflow:

<input type="file" name="folder" webkitdirectory directory multiple/>

Directory Chooser in HTML page

But, the issue is the folder gives only one file name in post array.

<?php 

echo "I am in page.";   

if ( empty($_POST['folder']))
{
    ?>
    <form method="POST">
        <div class="container compare_body">
            <div class="row">
                <div class="col-md-3">
                    Select a Folder:
                </div>
                <div class="col-md-3">
                    <input type="file" name="folder" webkitdirectory directory multiple/>
                </div>

                <div class="col-md-3">
                    <button type="submit" class="btn btn-info">List your files</button>
                </div>
            </div>
        </div>
    </form>

    <?php
}
else
{
    print_r($_POST['folder']);

    echo "I am in else.";

}
?>

I am in page.WWW.YIFY-TORRENTS.COM.jpgI am in else.

Edit : I tried GET method, which results in the following query:

http://localhost/thrillermovie/yourmovies?folder=2.png&folder=facebook_post.png&folder=callhistorycontrol.png&folder=khan.jpg&folder=minimization.png&folder=obama_knows.png&folder=facebook.png&folder=wildkrafts.png&folder=dekho.png&folder=sub.png&folder=2_batman.png&folder=best+response.png&folder=moore.png&folder=admob.png&folder=adrspeechcode.png&folder=batman_story.png&folder=comparemovies.png&folder=landevicefound.png&folder=it&folder=device-2015-08-19-005229.png&folder=bhakta.png&folder=Screenshot+from+2015-09-19+23%3A16%3A09.png&folder=arrow.png&folder=raghib_comment.png&folder=web_hi_res_512.png&folder=nfa_dfa.png&folder=raghiblul.png&folder=tux.png&folder=lexical.png&folder=likes.png&folder=raghib_lul.png&folder=bluegape.png&folder=con.png&folder=dfa_conversion.png&folder=bhakto+ko.png&folder=mynumber.png&folder=katjuJiReply.png&folder=tifY9AWf_400x400.jpg&folder=kalam.jpg&folder=bk.png&folder=1.png&folder=1_batman.png&folder=mealay.png

but output is only the last folder name.

Please help me to solve the problem.

Community
  • 1
  • 1
learner
  • 4,614
  • 7
  • 54
  • 98
  • 1
    You are receiving the _folder_ value in an indexed $_GET variable, such as $_GET['folder']. So, obviously there is only one entry with this index, namely the last one. You could add a counter to the key like *folder1=...&folder2=..., etc. – hherger Jan 27 '16 at 21:37
  • 1
    try the form name `name="folder[]"`and then process in foreach folder – Kneecht Jan 27 '16 at 21:39
  • Yep, good idea @Kneecht – hherger Jan 27 '16 at 21:40
  • @Kneecht It works. Thank you for help. Please give an answer so that I can accept. – learner Jan 27 '16 at 21:44
  • 1
    For the record, your question says that you are trying to get a folder name. However, the comment that you say works is going to get you an array of file names, not folder names. You should try to be a bit more clear as to what your specific problem is when asking questions. – Patrick Q Jan 27 '16 at 21:45
  • @PatrickQ Yes, I am sorry. I have edited the question. Thank you for insight. – learner Jan 27 '16 at 21:49

1 Answers1

1

try the form name name="folder[]" and then process in foreach folder

Kneecht
  • 93
  • 9